/* Base styles */
:root {
    --primary-red: #e60023;
    --light-gray: #efefef;
    --dark-gray: #767676;
    --pinterest-bg: #fff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Noto Sans KR", sans-serif;
    background-color: var(--pinterest-bg);
    color: #333;
    height: 100dvh;
    overflow: hidden;
}

/* 1. Header (Top Navigation) */
.header {
    width: calc(100% - 120px);
    display: flex;
    align-items: center;
    padding: 20px 14px 20px 0;
    gap: 10px;
    position: fixed;
    top: 0;
    background-color: var(--pinterest-bg);
    z-index: 1000; /* Ensure it stays on top */
    margin-bottom: 30px;
}

.header .logo {
    width: 32px;
    height: 32px;
    background-color: var(--primary-red);
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 20px;
    color: white;
    font-weight: bold;
    cursor: pointer;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 64px;
    margin-bottom: 16px;
}

.nav-links .nav-item {
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    text-decoration: none;
    color: #111;
    white-space: nowrap; /* Prevents text from wrapping */
}

.nav-links .nav-item.active {
    background-color: #111;
    color: white;
}

/* Search Bar */
.header .search-bar {
    flex-grow: 1; /* Takes up available space */
    position: relative;
}

.header .search-bar input {
    width: 100%;
    padding: 12px 40px; /* Space for icon */
    border: none;
    border-radius: 30px;
    background-color: var(--light-gray);
    font-size: 16px;
    outline: none;
}

.header .search-bar .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--dark-gray);
    pointer-events: none; /* Allows clicks to pass through */
}

/* Right Icons */
.header .right-icons {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header .right-icons .icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--light-gray);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.header .right-icons .icon-btn:hover {
    background-color: #ddd;
}

.header .right-icons .profile-pic {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #ccc;
    cursor: pointer;
}

/* 2. Main Container for Sidebar and Content */
.main-container {
    display: flex;
    height: 100%; /* Adjust based on header height */
}

/* 3. Left Sidebar */
.sidebar {
    width: 80px;
    padding-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    border-right: 1px solid var(--light-gray);
}

.sidebar .icon-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: transparent;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: #777;
    transition: background-color 0.2s;
}

.sidebar .icon-btn:hover {
    background-color: #ddd;
}

.sidebar .icon-btn.active {
    background-color: #333;
    color: white;
}

/* 4. Main Content Grid */
.content {
    flex-grow: 1;
    overflow-y: scroll; /* Enable scrolling */
    padding: 20px;
    padding-top: 82px;
}

.grid {
    position: relative; /* Required for Masonry */
    opacity: 0; /* Initially hide the entire grid */
    transition: opacity 0.5s ease-in-out; /* Smooth transition when showing */
}

.grid.loaded {
    opacity: 1; /* Show the grid once all images are loaded */
}

/* Masonry Sizers for column and gutter width */
.grid-sizer,
.grid-item {
    /* 5열 (5 columns) layout for desktop */
    width: calc(20% - 16px);
}

.gutter-sizer {
    width: 20px; /* Space between columns */
}

.grid-item {
    background-color: #f0f0f0; /* Placeholder background */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100px; /* Or a suitable minimum height for your loading state */
    position: relative; /* For positioning the loader */
    margin-bottom: 20px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    background-color: #fff;
    cursor: pointer;
}

.grid-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.grid-item img {
    display: none; /* Hide images initially */
    opacity: 0; /* Start with opacity 0 */
    transition: opacity 0.5s ease-in-out; /* Smooth fade-in for image */
    width: 100%;
}

.grid-item::before {
    content: "";
    display: block;
    width: 30px;
    height: 30px;
    border: 3px solid #ccc;
    border-top-color: #333;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.grid-item.image-loaded::before {
    display: none; /* Hide loader when image is loaded */
}

@keyframes spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

.grid-item.image-loaded img {
    display: block; /* Show image once loaded */
    opacity: 1;
}

/* Card with Text Content */
.grid-item .card-content {
    padding: 12px;
}

.grid-item .card-content h3 {
    margin: 0 0 8px 0;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
}

.grid-item .card-content .source {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: #888;
}

.grid-item .card-content .source .profile-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: #eee;
}

/* 5. Floating Button */
.floating-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: #ff8a82;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: grid;
    place-items: center;
    cursor: pointer;
    font-size: 24px;
    color: white;
    border: none;
    transition: background-color 0.2s;
    z-index: 999;
}

.floating-btn:hover {
    background-color: #ff9f98;
}

.filter {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.filter ul {
    display: flex;
    gap: 20px;
    padding: 0;
    margin: 0;
}

.filter li {
    list-style: none;
    cursor: pointer;
}

/* 6. Responsive Design */
@media (max-width: 1200px) {
    .grid-sizer,
    .grid-item {
        width: calc(25% - 15px);
    } /* 4 columns */
    .gutter-sizer {
        width: 20px;
    }
}

@media (max-width: 992px) {
    .grid-sizer,
    .grid-item {
        width: calc(33.333% - 13.333px);
    } /* 3 columns */
    .gutter-sizer {
        width: 20px;
    }
}

@media (max-width: 768px) {
    .nav-links {
        display: none;
    } /* Hide nav links */
    .grid-sizer,
    .grid-item {
        width: calc(50% - 10px);
    } /* 2 columns */
    .gutter-sizer {
        width: 20px;
    }
    .sidebar {
        display: none;
    } /* Hide sidebar on mobile */
    .main-container {
        height: auto;
    }
    .content {
        padding-top: 10px;
    }
    .header {
        width: calc(100% - 26px);
    }
    .content {
        height: 100dvh;
        padding-top: 112px;
    }
}

@media (max-width: 480px) {
    .grid-sizer,
    .grid-item {
        width: 100%;
    } /* 1 column */
    .gutter-sizer {
        width: 0;
    }
}

/* Custom icons (using Material Symbols) */
.material-symbols-outlined {
    font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
}

.flex {
    display: flex;
    width: 100%;
}

.flex > div {
    width: 50%;
}

.card {
    width: 50%;
    border-radius: 12px;
    border: 1px solid rgb(224 224 217);
    margin: 0 5%;
}

/* --- 최상위 컨테이너 --- */
.pinterest-detail-page-container {
    display: flex;
    flex-direction: column; /* 기본적으로 세로 배치 (모바일 우선) */
    width: 100%;
    background-color: #fff;
    border-radius: 16px; /* 둥근 모서리 */
    overflow: hidden; /* 자식 요소가 넘칠 경우 숨김 */
    position: relative; /* 뒤로가기 버튼 위치 조정을 위해 */
    gap: 20px;
}

/* --- 뒤로가기 버튼 --- */
.back-button {
    width: max-content;
    height: max-content;
    font-size: 32px; /* 아이콘 크기 */
    cursor: pointer;
    color: #333;
    z-index: 10; /* 다른 요소 위에 오도록 */
    padding: 5px; /* 클릭 영역 확보 */
    background-color: rgba(255, 255, 255, 0.8); /* 약간의 배경색 */
    border-radius: 50%; /* 원형 버튼 */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.back-button:hover {
    color: #888;
    background-color: rgba(240, 240, 240, 0.8);
}

/* --- 메인 핀 섹션 (좌측/상단) --- */
.main-pin-section {
    display: flex;
    flex-direction: row; /* 모바일: 이미지와 정보가 세로로 쌓임 */
    padding: 0;
    gap: 30px; /* 이미지와 정보 사이 간격 */
    border-bottom: 1px solid #eee; /* 관련 핀과의 구분선 */
    border-radius: 12px;
    width: 50%;
    /* max-width: 500px; */
}
