/* 
 * Elevator Selector Component 
 * ==========================================
 * Follows project style guidelines and variables.
 */

/* Fix for scrollbar jumping */
html {
  overflow-y: scroll;
}

:root {
  /* Ensure variables are available if not defined in global scope */
  --elevator-panel-bg: #FFFFFF;
  --elevator-panel-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

#elevator-selector {
  width: 100%;
  margin-top: 40px; /* Space from the brand grid */
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 10;
}

/* 
 * Toggle Button 
 * Matches the style of .btn-primary but adapts width to match brand card
 */
#elevator-toggle-btn {
  /* Width calculation to match one card in a 3-column grid with 40px gap */
  width: calc((100% - 80px) / 3); 
  min-width: 280px;
  max-width: 400px;
  height: auto; /* Height 1/2 ~ 1/3 of brand card (brand card is ~250px high) -> ~80px */
  padding: 18px 24px;
  
  background: var(--primary-blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 15px rgba(22, 93, 255, 0.25);
  
  font-family: var(--font-main);
  font-size: 1.1rem;
  font-weight: 600;
  
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  
  cursor: pointer;
  transition: var(--transition-smooth);
  outline: none;
  
  /* Icon rotation wrapper */
}

#elevator-toggle-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(22, 93, 255, 0.35);
}

#elevator-toggle-btn .arrow-icon {
  transition: transform 0.3s ease-out;
  width: 20px;
  height: 20px;
  fill: currentColor;
}

#elevator-toggle-btn.active .arrow-icon {
  transform: rotate(180deg);
}

/* 
 * Selection Panel 
 */
#elevator-panel {
  width: 100%;
  max-width: 1200px; /* Match container width */
  background: var(--elevator-panel-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--elevator-panel-shadow);
  border: 1px solid var(--border-color);
  
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  
  /* Animation */
  transition: max-height 0.3s ease-out, opacity 0.3s ease-out, margin-top 0.3s ease-out;
  
  margin-top: 0;
}

#elevator-panel.open {
  max-height: 2000px; /* Sufficiently large value */
  opacity: 1;
  margin-top: 24px;
  padding: 30px;
}

/* Grid Layout */
.elevator-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

/* Card Style */
.elevator-card {
  background: var(--bg-base);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transition: var(--transition-smooth);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.elevator-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary-blue);
  box-shadow: 0 8px 20px rgba(22, 93, 255, 0.1);
  background: #fff;
}

/* Icon */
.elevator-icon-wrapper {
  width: 100%;
  aspect-ratio: 16/9;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(22, 93, 255, 0.05);
  border-radius: 6px;
  color: var(--primary-blue);
  overflow: hidden;
}

.elevator-icon {
  width: 100%;
  height: 100%;
  transition: transform 0.2s ease-out;
  will-change: transform;
}

.elevator-card:hover .elevator-icon {
  transform: scale(1.1);
}

/* Text */
.elevator-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
}

.elevator-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Loading State */
.elevator-loading {
  padding: 40px;
  text-align: center;
  color: var(--text-secondary);
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(22, 93, 255, 0.2);
  border-top-color: var(--primary-blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

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

/* Responsive */
@media (max-width: 992px) {
  #elevator-toggle-btn {
    width: 60%;
  }
  .elevator-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  #elevator-toggle-btn {
    width: 100%;
  }
  .elevator-grid {
    grid-template-columns: 1fr;
  }
  #elevator-panel.open {
    padding: 20px;
  }
}

/* Modal Overlay */
.elevator-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  z-index: 20000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease-in, visibility 0.2s ease-in;
  padding: 20px;
  cursor: pointer; /* Hint that the whole area is clickable */
}

.elevator-modal-overlay.visible {
  opacity: 1;
  visibility: visible;
}

/* Modal Content */
.elevator-modal {
  background: var(--bg-base);
  width: 100%;
  max-width: 800px;
  border-radius: var(--radius-md);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  position: relative;
  transform: translateY(20px);
  transition: transform 0.3s ease-in;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 90vh;
  outline: none;
  cursor: pointer; /* Click inside also closes unless on interactive element */
}

.elevator-modal-overlay.visible .elevator-modal {
  transform: translateY(0);
}

/* Modal Header */
.elevator-modal-header {
  padding: 20px 30px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
}

.elevator-modal-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 12px;
}

.elevator-modal-icon {
  width: 2px;
  height: 28px;
  color: var(--primary-blue);
}

.elevator-modal-close-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  pointer-events: none; /* Let clicks pass through to container */
}

.hand-icon {
  width: 20px;
  height: 20px;
  animation: tapHint 2s infinite ease-in-out;
}

@keyframes tapHint {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.1); opacity: 1; }
}

/* Interactive Elements inside Modal should have default cursor */
.elevator-modal button,
.elevator-modal a,
.elevator-modal input,
.elevator-modal select,
.elevator-modal textarea,
.elevator-modal [role="button"] {
  cursor: pointer;
}

.elevator-modal-image-wrapper,
.elevator-modal-details {
  cursor: pointer; /* Ensure clicks here bubble up */
}

/* Modal Body */
.elevator-modal-body {
  flex: 1;
  min-height: 0;
  padding: 30px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  align-items: start;
}

/* Image Section */
.elevator-modal-image-wrapper {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  background: #f0f2f5;
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
}

.elevator-modal-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.elevator-modal-image-wrapper:hover .elevator-modal-image {
  transform: scale(1.05);
}

/* Details Section */
.elevator-detail-section {
  margin-bottom: 24px;
}

.elevator-detail-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 8px;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.elevator-detail-text {
  font-size: 1.05rem;
  color: var(--text-main);
  line-height: 1.6;
}

.elevator-tag {
  display: inline-block;
  background: var(--bg-blue-tint);
  color: var(--primary-blue);
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.9rem;
  margin-right: 8px;
  margin-bottom: 8px;
  font-weight: 500;
}

/* Responsive */
@media (max-width: 768px) {
  .elevator-modal-body {
    grid-template-columns: 1fr;
    padding: 20px;
  }
  
  .elevator-modal-title {
    font-size: 1.25rem;
  }
}
