/* ===========================================
   RESPONSIVE STAFF PAGE STYLES - ADVANCED FLEXBOX LAYOUT
   =========================================== */

/* ===========================================
   GLOBAL STYLES & RESET
   =========================================== */

* {
  box-sizing: border-box;
}

/* On mobile widths, remove the extra right padding trick to avoid visible white gutters */
@media (max-width: 767px) {
  .info-text {
    padding-right: 0;
    margin-right: 0;
  }
}

html, body {
  max-width: 100%;

}

body {
  margin: 0;
  padding: 0;
}

/* ===========================================
   STAFF PAGE LAYOUT
   =========================================== */

.staff-body {
  min-height: 100vh;
  background-color: #f8f9fa;
  padding: 20px 0;
  width: 100%;
}

.staff-header {
  font-size: 2.5rem;
  color: #094d6b;
  text-align: center;
  margin-bottom: 50px;
  margin-top: 20px;
  font-weight: 700;
}

#staff-container {
  max-width: 1320px; /* Fits 4 x 300px + 3 x 12px gaps + gutters */
  margin: 0 auto;
  padding: 0 20px;
}

.error-message {
  text-align: center;
  color: #dc3545;
  font-size: 1.1rem;
  padding: 20px;
}

/* ===========================================
   SUBJECT SECTIONS - MINIMAL SPACING
   =========================================== */

.subject-section {
  margin-bottom: 30px; /* Minimal spacing - no extra padding */
  transition: none; /* No dynamic spacing changes */
}

.subject-header {
  margin-bottom: 30px;
}

.subject-title {
  font-size: 1.8rem;
  color: #094d6b;
  font-weight: 600;
  border-bottom: 3px solid #094d6b;
  padding-bottom: 10px;
  display: inline-block;
}

/* ===========================================
   FLEXBOX LAYOUT - CONSISTENT SPACING
   =========================================== */

.staff-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, 300px);
  gap: 12px; /* Consistent spacing */
  position: relative;
  contain: layout; /* Prevent layout recalculation issues */
  justify-content: start; /* align grid to the left */
  justify-items: start;  /* align items to the left in their cells */
}

/* ===========================================
   FLIP MODE (D): flip card to show text
   =========================================== */

/* Base 3D structure (safe for all modes) */
.staff-card {
  perspective: 1000px;
}
.staff-card-inner {
  position: relative;
  width: 100%;
  height: 100%; /* fill the card to flip the entire surface */
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}
.card-face {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 15px;
  overflow: hidden;
}
.card-front { z-index: 2; }
.card-back {
  transform: rotateY(180deg);
  background: #fff;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}
.flip-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
}

/* Activate flip only in flip mode */
body.mode-flip .staff-expanded-info { display: none !important; }
body.mode-flip .staff-member { grid-column: span 1 !important; }
body.mode-flip .staff-card.flipped .staff-card-inner { transform: rotateY(180deg); animation: shadowFlip 0.8s ease forwards;}
body.mode-flip .staff-overlay { opacity: 0.95; }
/* In flip mode, avoid overlay hover slide which can look like only the image moves */
body.mode-flip .staff-card:hover .staff-overlay { transform: translateY(0); }
/* Ensure enough space to display ~150 characters on desktop */
/* Whole card flips and controls size (no extra height for back only) */
body.mode-flip .staff-card.flipped {
  min-height: 0;
  aspect-ratio: 1 / 1; /* keep square when flipped too */
}


/* Ensure panel never shows on mobile */
@media (max-width: 767px) {
  .staff-expanded-info { display: none !important; }
}

/* ===========================================
   STAFF MEMBER CARDS - SMOOTH TRANSITIONS
   =========================================== */

.staff-member {
  display: flex;
  flex-direction: row;
  transition: none; /* Avoid animating layout-sized elements */
  transform-origin: left center; /* Prevent jumping during transitions */
  contain: layout; /* Optimize layout performance */
}

/* Desktop: Always horizontal flexbox - prevents layout shifts */
@media (min-width: 768px) {
  .staff-member {
    flex-direction: row;
    align-items: flex-start;
  }
}

/* Mobile: Vertical flexbox for bottom expansion */
@media (max-width: 767px) {
  .staff-member {
    flex-direction: column;
    align-items: stretch; /* Match widths for card and expanded info */
  }
  .staff-grid{
    justify-content: center;
  }
  .subject-header{
    text-align: center;
  }
}

/* ===========================================
   CARD STYLING - CONSISTENT DIMENSIONS
   =========================================== */

.staff-card {
  background: #ffffff;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: all 0.18s ease-out; /* Faster */
  cursor: pointer;
  position: relative;
  width: 300px;
  height: 300px;
  max-width: 300px;
  min-width: 300px;
  flex-shrink: 0; /* Card maintains size while container flexes */
  contain: paint; /* Optimize rendering */
  perspective: 1000px; /* ensure 3D perspective is applied at card level */
}

/* Card size is unified at 300x300 across breakpoints */

/* (Handled above) */

.staff-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.staff-card.active {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(9, 77, 107, 0.2);
  border: 2px solid #094d6b;
}

/* ===========================================
   CARD IMAGE SECTION
   =========================================== */

.staff-image-container {
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

.staff-image {
  width: 100%;
  height: 100%;
  object-fit: contain; /* No cropping, no stretching */
  object-position: center;
  background: #f2f2f2; /* Neutral background for letterboxing */
  transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

.staff-card:hover .staff-image {
  transform: scale(1.05);
}

.staff-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(9, 77, 107, 0.95));
  color: white;
  padding: 20px;
  transform: translateY(100%);
  transition: transform 0.2s ease-out;
}

.staff-card:hover .staff-overlay,
.staff-card.active .staff-overlay {
  transform: translateY(0);
}

/* Disable hover-only effects on touch devices */
@media (hover: none), (pointer: coarse) {
  .staff-card:hover {
    transform: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  }
  .staff-card:hover .staff-image {
    transform: none;
  }
  .staff-card:hover .staff-overlay {
    transform: translateY(100%);
  }
}

.staff-name {
  font-size: 1.3rem;
  font-weight: 600;
  margin: 0 0 8px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.staff-title {
  font-size: 0.95rem;
  margin: 0;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===========================================
   SLIDING PANEL - CONTROLLED EXPANSION WITHOUT FLASHING
   =========================================== */

.staff-expanded-info {
  position: relative;   /* keep it in the flow of the card */
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  border: 2px solid #094d6b;
  overflow: hidden;
  opacity: 0;
  transform-origin: left center;
}

/* Flip-only final design: hide legacy expanded panel */
.staff-expanded-info { display: none !important; }

/* Desktop: Strict slider control - SAME LAYER as cards, no overlap */
@media (min-width: 768px) {
  .staff-expanded-info {
    height: 320px; /* Fixed height for consistent layout */
    width: 0; /* Start completely collapsed horizontally */
    margin-left: 20px; /* Spacing between card and info */
    margin-right: 0;  /* Avoid extra width inside the active item */
    flex-shrink: 0;
    flex-grow: 0; /* NEVER grow beyond set width */
    min-width: 0;
    max-width: 0; /* Start with zero max-width */
    position: relative;
    z-index: 1; /* SAME layer as cards - no overlap */
    overflow: hidden;
    transform-origin: left center;
    transform: translateX(-16px); /* slide-in start */
    transition:
      width 2s cubic-bezier(0.3, 0.7, 0.2, 1),
      transform 2s cubic-bezier(0.3, 0.7, 0.2, 1),
      opacity 1.2s ease 0.2s; /* fade slightly trails the wipe */
  }
  
  .staff-expanded-info.active {
      display: block;       /* show when active */
    width: 300px; /* Fixed width */
    max-width: 300px; /* Hard limit */
    min-width: 300px; /* No shrinking below this */
    opacity: 1;
    z-index: 1; /* Same layer as cards */
    transform: translateX(0); /* slide-in end */
  }
  
  /* Additional safety: prevent any flex expansion */
  .staff-expanded-info,
  .staff-expanded-info.active {
    flex-basis: auto !important;
    flex-grow: 0 !important;
    flex-shrink: 0 !important;
  }
  
  /* Ensure slider never goes to screen edge or overlaps */
  .staff-grid .staff-expanded-info.active {
    position: relative;
    right: auto;
    left: auto;
    max-width: 300px !important; /* Align with fixed width */
    z-index: 1; /* Same layer enforcement */
  }
}

/* Mobile: Slide to the bottom */
@media (max-width: 767px) {
  .staff-expanded-info {
    margin-top: 15px;
    margin-left: 0;
    margin-right: 0;
    max-height: 0;
    width: 100%; /* Matches the card width due to parent align-items: stretch */
    max-width: 100%;
    overflow: hidden;
    transform: translateY(-10px); /* slide-down start */
    transition:
      max-height 1.6s ease,
      transform 1.6s ease,
      opacity 1s ease 0.15s; /* slight delay for wipe feel */
  }
  
  .staff-expanded-info.active {
    max-height: 400px;
    opacity: 1;
  }

  /* Flip mode mobile optimizations */
  body.mode-flip .staff-card { width: 100%; max-width: 100%; }
  /* Keep image 1:1 when not flipped */
  body.mode-flip .staff-card:not(.flipped) { aspect-ratio: 1 / 1; }
  /* When flipped on mobile, keep square; back content scrolls if longer */
  body.mode-flip .staff-card.flipped {
    aspect-ratio: 1 / 1;
    height: auto;
    min-height: 0;
  }
  body.mode-flip .flip-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}


/* ===========================================
   PANEL CONTENT - TOP ALIGNED WITH HIDDEN SCROLL
{{ ... }}
   =========================================== */

.staff-info-content {
  padding: 16px; /* Reduce padding to remove large white space */
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start; /* Start from top */
  min-width: 200px;
  overflow: hidden;
}

.close-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  cursor: pointer;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  z-index: 10;
}

.close-btn:hover {
  background-color: #f0f0f0;
  color: #094d6b;
}

.staff-details {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding-right: 10px; /* Minimal space for hidden scrollbar */
}

.staff-details h4,
.flip-content h4 {
  font-size: 1.4rem;
  color: #094d6b;
  margin: 0 0 10px 0;
  font-weight: 600;
  width: 100%;
}

.staff-details .position,
.flip-content .position {
  font-size: 1rem;
  color: #666;
  margin: 0 0 8px 0;
  font-weight: 500;
  width: 100%;
}

.staff-details .subject,
.flip-content .subject {
  font-size: 0.9rem;
  color: #094d6b;
  margin: 0 0 15px 0;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 100%;
}

/* ===========================================
   SCROLLABLE TEXT WITH COMPLETELY HIDDEN SCROLLBAR
   =========================================== */

.info-text {
  color: #333;
  line-height: 1.6;
  font-size: 0.95rem;
  flex: 1;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  
  /* Complete scrollbar removal for all browsers */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* Internet Explorer and Edge */
  
  /* Additional padding technique for complete invisibility */
  padding-right: 16px;
  margin-right: -16px;
}

/* Hide scrollbar for WebKit browsers (Chrome, Safari, Edge) */
.info-text::-webkit-scrollbar {
  display: none;
  width: 0 !important;
  height: 0 !important;
  background: transparent;
  -webkit-appearance: none;
}

/* Ensure text starts from top */
.info-text > *:first-child {
  margin-top: 0 !important;
  padding-top: 0 !important;
}

.info-text > *:last-child {
  margin-bottom: 0 !important;
  padding-bottom: 0 !important;
}

/* ===========================================
   RESPONSIVE ADJUSTMENTS
   =========================================== */

@media (max-width: 480px) {
  .staff-header {
    font-size: 2rem;
  }
  
  .subject-title {
    font-size: 1.5rem;
  }
  
  /* Allow natural height so flip back content is readable */
  .staff-card { height: auto; }
  
  .staff-name {
    font-size: 1.2rem;
  }
  
  .staff-title {
    font-size: 0.9rem;
  }
  
  .staff-overlay {
    padding: 15px;
  }
  
  .staff-info-content {
    padding: 12px; /* Smaller padding on small phones */
  }
  
  #staff-container {
    padding: 0 15px;
  }
  
  .staff-body {
    padding: 15px 0;
  }
  
  .staff-expanded-info.active {
    max-height: 300px;
  }
  
  .staff-grid {
    gap: 12px; /* Slightly tighter small-mobile spacing */
  }
}

/* ===========================================
   ACCESSIBILITY & INTERACTIONS
   =========================================== */

.staff-card:focus {
  outline: 3px solid #094d6b;
  outline-offset: 2px;
}

.close-btn:focus {
  outline: 2px solid #094d6b;
  outline-offset: 1px;
}

/* Smooth animations for better UX */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* ===========================================
   PERFORMANCE OPTIMIZATIONS
   =========================================== */

/* Hardware acceleration for smooth animations */
.staff-member,
.staff-card,
.staff-expanded-info {
  will-change: transform, opacity, width;
}

/* GPU-accelerated transforms */
.staff-card:hover,
.staff-card.active,
.staff-overlay {
  transform: translateZ(0); /* Force GPU acceleration */
}

/* Smooth text rendering during animations */
.staff-details * {
  text-rendering: optimizeSpeed;
  -webkit-font-smoothing: subpixel-antialiased;
}

/* Mode-specific behaviors removed; Flip is final design */
@keyframes shadowFlip {
  0% {
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);   /* flat */
  }
  25% {
    box-shadow: 12px 4px 20px rgba(0,0,0,0.08); /* tilting right */
  }
  50% {
    box-shadow: 0 4px 5px rgba(0,0,0,0.06);   /* edge-on, very faint */
  }
  75% {
    box-shadow: -12px 4px 20px rgba(0,0,0,0.08); /* tilting left */
  }
  100% {
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);   /* flat again */
  }
}
