/* ===========================
   STYLE SELECTOR MODAL
   =========================== */

/* Style Modal Overlay */
.modal-overlay#styleModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: transparent;
  z-index: 10000;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 100px;
  pointer-events: none;
  backdrop-filter: none;
}

.modal-overlay#styleModal.active {
  display: flex;
}

.modal-overlay#styleModal .style-modal {
  pointer-events: auto;
}

/* Style Modal Container */
.style-modal {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  border-radius: 20px;
  width: 410px; /* Balanced width for proper spacing */
  max-height: 70vh;
  overflow: hidden; /* Keep for container, but body allows expansion */
  position: relative;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.15);
  animation: modalSlideIn 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
  padding: 20px;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Modal Header */
.style-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 10px; /* Minimal spacing */
}

.style-modal-title-wrapper {
  flex: 1;
}

.style-modal-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: #ffffff;
  margin: 0 0 4px 0;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-size: 0.85rem;
}

.style-modal-subtitle {
  font-size: 0.7rem;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.6);
  margin: 0;
  letter-spacing: 0.3px;
}

.style-modal .close-modal {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  line-height: 1;
}

.style-modal .close-modal:hover {
  color: #ffffff;
  background: rgba(255, 77, 79, 0.2);
  border-color: rgba(255, 77, 79, 0.4);
  transform: scale(1.1);
}

/* Modal Body */
.style-modal-body {
  padding: 15px 15px 10px 15px; /* Reduced bottom padding */
  max-height: calc(70vh - 80px); /* Increased to match modal height */
  overflow-y: auto !important; /* CRITICAL: Enable scroll */
  overflow-x: hidden; /* Prevent horizontal scroll */
}

.style-modal-body::-webkit-scrollbar {
  width: 6px;
}

.style-modal-body::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

.style-modal-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 8px;
}

.style-modal-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Style Sections - Unified Interface (no headers) */
.style-section {
  margin-bottom: 0; /* Unified grid, no separation */
}

.style-section:last-child {
  margin-bottom: 0;
}

/* Hide section headers */
.style-section-header {
  display: none !important;
}

.style-section-title {
  display: none !important;
}

/* Hide add style button */
.add-style-btn {
  display: none !important;
}

/* Hide default styles section completely */
.default-styles-section {
  display: none !important;
}

/* Custom styles section now takes full space */
.custom-styles-section {
  margin-top: 0 !important;
  padding-top: 0 !important;
  border-top: none !important;
}

/* Styles Grid */
.styles-grid {
  display: grid;
  grid-template-columns: repeat(3, 99px); /* 10% smaller circles */
  gap: 22.5px; /* 10% smaller gap for hover expansion */
  justify-content: center;
  align-items: flex-start;
  overflow: visible !important; /* Fix hover trimming */
  max-width: 100%;
  padding: 0; /* No extra padding - let body padding handle it */
  margin: 0 auto; /* Center the grid */
}

/* Style Card - Circular Pill Design */
.style-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  padding: 0; /* Remove padding to let grid gap control spacing */
  border-radius: 50px;
  background: transparent;
  border: none;
  overflow: visible !important; /* Prevent hover trimming */
  z-index: 1;
}

.style-card:hover {
  transform: translateY(-2px);
  z-index: 10; /* Bring to front on hover */
}

.style-card:active {
  transform: translateY(0);
}

/* Create Style Card */
.style-card.create-style .style-card-image {
  border: 2px dashed rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.03);
}

.style-card.create-style:hover .style-card-image {
  border-color: rgba(76, 175, 80, 0.5);
  background: rgba(76, 175, 80, 0.08);
  box-shadow: 0 8px 24px rgba(76, 175, 80, 0.3), 0 0 30px rgba(76, 175, 80, 0.2);
}

.style-card.create-style .style-card-title {
  font-size: 2rem;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.5);
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
}

.style-card.create-style:hover .style-card-title {
  opacity: 0;
}

.style-card.create-style .style-card-pill-details {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.9);
  box-shadow: none;
  text-align: center;
  line-height: 1.2;
}

/* Style Card Image Preview - Circular */
.style-card-image {
  width: 99px; /* 10% smaller */
  height: 99px; /* 10% smaller */
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.04) 100%);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: all 0.25s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  position: relative !important;
}

.style-card:hover .style-card-image {
  background: linear-gradient(135deg, rgba(103, 126, 234, 0.2) 0%, rgba(118, 75, 162, 0.15) 100%);
  border-color: rgba(103, 126, 234, 0.5);
  box-shadow: 0 8px 24px rgba(103, 126, 234, 0.3), 0 0 30px rgba(103, 126, 234, 0.2);
  transform: scale(1.08);
}

/* Inline confirm pill overlay for delete */
.confirm-pill {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 12, 24, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1000;
  backdrop-filter: saturate(140%) blur(2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

.confirm-pill .confirm-message {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.confirm-pill .confirm-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.confirm-pill .confirm-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}

.confirm-pill .confirm-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.confirm-pill .confirm-yes {
  border-color: rgba(255, 99, 99, 0.45);
  background: rgba(255, 99, 99, 0.15);
}

.confirm-pill .confirm-yes:hover {
  background: rgba(255, 99, 99, 0.25);
}

.style-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(0.7); /* 30% darker by default */
  opacity: 0;
  transition: opacity 0.5s ease, filter 0.3s ease;
}

.style-card-image img.loaded {
  opacity: 1;
}

.style-card:hover .style-card-image img {
  filter: brightness(1); /* 100% brightness on hover */
}

.style-card-image-placeholder {
  display: none;
}

/* Style Card Title - Inside Circle */
.style-card-title {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  text-align: center;
  line-height: 1.2;
  max-width: 90px;
  white-space: normal;
  word-wrap: break-word;
  padding: 0;
  transition: color 0.25s ease;
  z-index: 2;
}

.style-card:hover .style-card-title {
  color: #ffffff;
}

.style-card-header {
  display: none;
}

.style-card-icon {
  display: none;
}

/* Hide description and cues for circular design */
.style-card-description {
  display: none;
}

.style-card-cues {
  display: none;
}

.style-card-cue-tag {
  display: none;
}

/* Hover Message - Pill Style in Center */
.style-card-pill-details {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(0, 0, 0, 0.3); /* 30% dark background */
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  padding: 5px 11px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
  box-shadow: none;
  z-index: 100;
  pointer-events: none;
  white-space: nowrap;
  font-size: 0.65rem;
  font-weight: 700;
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.style-card:hover .style-card-pill-details {
  opacity: 1;
  visibility: visible;
}

.style-card:hover .style-card-title {
  opacity: 0;
}

.style-card-pill-detail {
  display: none;
}

.style-card-pill-detail-label {
  display: none;
}

.style-card-pill-detail-value {
  display: none;
}

/* Custom Style Badge */
.custom-badge {
  display: inline-block;
  font-size: 0.6rem;
  padding: 1px 6px;
  background: rgba(103, 126, 234, 0.2);
  border: 1px solid rgba(103, 126, 234, 0.4);
  color: #667eea;
  border-radius: 3px;
  margin-top: 4px;
  font-weight: 500;
}

/* Delete Button for Custom Styles */
.delete-style-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: rgba(244, 67, 54, 0.2);
  border: 1px solid rgba(244, 67, 54, 0.4);
  border-radius: 50%;
  color: #f44336;
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.style-card:hover .delete-style-btn {
  display: flex;
}

.delete-style-btn:hover {
  background: rgba(244, 67, 54, 0.3);
  border-color: #f44336;
  transform: scale(1.1);
}

/* Empty State */
.styles-empty-state {
  text-align: center;
  padding: 30px 15px;
  color: rgba(255, 255, 255, 0.6);
  grid-column: 1 / -1;
}

.styles-empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
  opacity: 0.4;
}

.styles-empty-state-text {
  font-size: 0.85rem;
  line-height: 1.4;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .style-modal {
    width: 350px;
    max-height: 60vh;
    border-radius: 16px;
    padding: 16px;
    margin-left: 0;
    /* CRITICAL FIX: Ensure modal itself is fully visible and opaque on mobile */
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%) !important;
    opacity: 1 !important;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
  }

  .modal-overlay#styleModal {
    padding-bottom: 80px;
    /* MOBILE FIX: Keep overlay transparent (no dark background behind modal) */
    background-color: rgba(0, 0, 0, 0.3) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  .style-modal-header {
    padding: 0 0 12px 0;
    margin-bottom: 16px;
  }

  .style-modal-header h2 {
    font-size: 0.8rem;
  }

  .style-modal-body {
    max-height: calc(60vh - 70px);
    overflow-y: auto !important; /* CRITICAL: Enable scroll on mobile */
    overflow-x: hidden;
  }

  .styles-grid {
    grid-template-columns: repeat(3, 90px);
    gap: 12px;
  }

  .style-card {
    padding: 6px;
    /* MOBILE FIX: Click once to apply style (no hover state needed) */
    cursor: pointer;
  }

  .style-card-image {
    width: 90px;
    height: 90px;
    position: relative !important;
  }

  .style-card-title {
    font-size: 0.7rem;
    max-width: 75px;
  }

  .style-card-pill-details {
    font-size: 0.65rem;
    padding: 5px 10px;
  }
  
  /* CRITICAL FIX: Disable animation on mobile - show cards immediately */
  .style-card {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }

  /* MOBILE FIX: Ensure style images are visible (override fade-in dependency) */
  .style-card-image img {
    opacity: 1 !important;
    transition: none !important;
  }
  
  /* MOBILE FIX: Make all modal text fully opaque and readable */
  .style-modal,
  .style-modal p,
  .style-modal h1,
  .style-modal h2,
  .style-modal h3,
  .style-modal h4,
  .style-modal .style-modal-subtitle,
  .style-modal .style-card-title,
  .style-modal .styles-empty-state,
  .style-modal .styles-empty-state-text,
  .style-modal .confirm-pill .confirm-message {
    color: #ffffff !important;
    opacity: 1 !important;
    text-shadow: none !important;
  }
}

/* Animation for style cards appearing */
.style-card {
  animation: styleCardFadeIn 0.25s ease forwards;
  opacity: 0;
}

@keyframes styleCardFadeIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.style-card:nth-child(1) { animation-delay: 0.03s; }
.style-card:nth-child(2) { animation-delay: 0.06s; }
.style-card:nth-child(3) { animation-delay: 0.09s; }
.style-card:nth-child(4) { animation-delay: 0.12s; }
.style-card:nth-child(5) { animation-delay: 0.15s; }
.style-card:nth-child(6) { animation-delay: 0.18s; }

/* Loading Spinner - perfectly centered in the card */
.style-loading-spinner {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  width: 40px;
  height: 40px;
  margin-top: -20px !important;  /* Half of height */
  margin-left: -20px !important; /* Half of width */
  z-index: 10;
}

.style-loading-spinner::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spinCentered 0.8s linear infinite;
}

@keyframes spinCentered {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Processing state for create card */
.style-card.create-style[style*="pointer-events: none"] {
  opacity: 0.8;
  cursor: not-allowed;
}

.style-card.create-style[style*="pointer-events: none"] .style-card-image {
  background: linear-gradient(135deg, rgba(34, 193, 195, 0.2) 0%, rgba(45, 253, 185, 0.2) 100%);
}

/* Custom styles section - unified interface */
.custom-styles-section {
  margin-top: 0 !important;
  padding-top: 0 !important;
  border-top: none !important;
}

.custom-styles-section h3 {
  display: none !important; /* Hide header */
}
