/* Portfolio Section */
#portfolio {
    position: relative;
    padding: 80px 0;
    background: #fff;
    margin-bottom: 40px;
}

/* Navigation Controls */
.portfolio-nav {
    margin: 0 auto 40px;
    padding: 0 20px;
    max-width: 800px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.category-switch,
.subcategory-switch {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.portfolio-nav button {
    background: none;
    border: 1px solid #666;
    padding: 8px 16px;
    font-size: 1.1rem;
    cursor: pointer;
    color: #666;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.portfolio-nav button.active {
    border-color: #000;
    color: #000;
    font-weight: 600;
    background: rgba(0,0,0,0.05);
}

.portfolio-nav button:hover {
    border-color: #000;
    color: #000;
    background: rgba(0,0,0,0.03);
}

/* Portfolio Grid */
.portfolio-container {
    position: relative;
    margin: 60px 0;
}

.portfolio-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
    padding: 2rem;
    max-width: 1800px;
    margin: 0 auto;
}

.portfolio-item {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s, transform 0.5s;
}

.portfolio-item.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Project Preview */
.project-preview {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: 8px;
    background: #f5f5f5;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.project-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.3s;
}

.project-preview img:hover {
    transform: scale(1.08);
    box-shadow: 0 0 10px #333;
}

.project-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1.5rem;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    color: white;
    transform: translateY(100%);
    transition: transform 0.3s;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.project-preview:hover .project-info {
    transform: translateY(0);
}

.project-info h3 {
    font-size: 1.5rem;
    margin: 0;
}

.project-info p {
    font-size: 1rem;
    margin: 0;
}

.gallery-btn, .view-gallery {
    background: white;
    color: black;
    border: none;
    padding: 10px 20px;
    margin-top: 10px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 1rem;
    transition: background 0.3s;
    text-decoration: none;
    display: inline-block;
}

.gallery-btn:hover, .view-gallery:hover {
    background: #eee;
}

/* Gallery Grid Styles */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 2rem;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.gallery-grid img {
    width: 100%;
    aspect-ratio: 16/9;
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    background: #eaeaea;
}

.gallery-grid img:hover {
    transform: scale(1.04);
    box-shadow: 0 4px 24px rgba(0,0,0,0.13);
}

/* Lightbox Overlay Styles */
.lightbox {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(255, 255, 255, 0.96);
    justify-content: center;
    align-items: center;
    z-index: 10000;
    flex-direction: row;
    animation: fadeIn 0.3s;
    overflow-y: auto; /* Enable vertical scrolling */
}

.lightbox.active {
    display: flex;
}

.lightbox-content {
    position: relative;
    max-width: 90%;
    max-height: 90vh;
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 0;
}

.lightbox img {
    max-width: calc(100% - 4rem);
    max-height: calc(100% - 4rem);
    width: auto;
    height: auto;
    object-fit: cover; /* Fills the lightbox and crops if needed */
    border-radius: 14px;
    box-shadow: 0 0 32px #000;
    background: #222;
}

.lightbox img.no-crop {
    object-fit: contain !important;
}

.lightbox-arrow {
    background: rgba(0,0,0,0.5);
    color: #fff;
    border: none;
    font-size: 2.5rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    z-index: 10001;
    border-radius: 4px;
    margin: 0 1rem;
    position: relative;
}

.lightbox-close {
    position: absolute;
    top: 30px;
    right: 40px;
    background: none;
    color: #fff;
    border: none;
    font-size: 3rem;
    cursor: pointer;
    z-index: 10002;
}

/* Gallery Header - Apple Inspired */
.gallery-header {
    padding: 3rem 1rem 2rem 1rem;
    text-align: center;
    background: linear-gradient(120deg, #f8f9fa 0%, #e9ecef 100%);
    box-shadow: 0 4px 24px rgba(0,0,0,0.04);
    margin-bottom: 2.5rem;
    border-radius: 0 0 32px 32px;
    position: relative;
}

.gallery-header h1 {
    font-size: 3rem;
    font-weight: 700;
    margin: 0 0 0.5rem 0;
    letter-spacing: 1px;
    color: #222;
    background: linear-gradient(90deg, #222, #888 70%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.gallery-header p {
    color: #555;
    font-size: 1.25rem;
    margin: 0.5rem 0 0 0;
    font-weight: 400;
    letter-spacing: 0.2px;
}

/* Sleek Return Button */
.return-button {
    display: inline-block;
    margin: 1rem 0 0 0;
    padding: 0.7rem 1.6rem;
    background: linear-gradient(90deg, #e3e6ea 0%, #f7f8fa 100%);
    color: #222;
    text-decoration: none;
    border-radius: 24px;
    font-size: 1.05rem;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(255, 255, 255, 0.06);
    border: 1px solid #ffffff;
    transition: background 0.2s, box-shadow 0.2s, color 0.2s;
    position: absolute;
    left: 2rem;
    top: 2rem;
}

.return-button:hover {
    background: linear-gradient(90deg, #d1d5db 0%, #e3e6ea 100%);
    color: #0071e3;
    box-shadow: 0 4px 16px rgba(0,0,0,0.10);
    border-color: #cfd8dc;
}

/* Responsive */
@media (max-width: 1200px) {
    .portfolio-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .portfolio-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 1rem;
    }
    .gallery-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 1rem;
    }
    .project-info {
        padding: 1rem;
    }
    .lightbox img {
        max-width: 95vw;
        max-height: 70vh;
    }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Unified overlay / lightbox rules */
.gallery-overlay,
#gallery-view,
.lightbox {
  display: none;                /* hidden until opened by JS */
  position: fixed;
  inset: 0;                     /* top:0; right:0; bottom:0; left:0; */
  z-index: 10000;
  align-items: flex-start;      /* Changed from center to allow scrolling */
  justify-content: center;
  background: rgba(20,24,28,0.96);
  pointer-events: none;         /* don't block interactions when hidden */
  overflow-y: auto;             /* Enable vertical scrolling */
  padding: 40px 0;              /* Add padding to ensure content isn't flush with edges */
}

/* visible state */
.gallery-overlay.active,
#gallery-view.active,
.lightbox.active {
  display: flex;                /* use flex for centering */
  pointer-events: auto;
}

/* Safer sizing for lightbox content to avoid 100vh/vw issues on mobile */
.lightbox img {
  max-width: calc(100% - 4rem);
  max-height: calc(100% - 4rem);
  width: auto;
  height: auto;
  object-fit: cover;
}

/* Body lock when lightbox is open to prevent background scrolling */
body.lightbox-open {
  overflow: hidden;
}