/**
 * Advanced Post Grid - Instagram Style CSS
 * Instagram Post 風格樣式
 */

/* 主容器 */
.apg-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 10px;
}

/* 篩選按鈕 - 隱藏 */
.apg-filters {
    display: none;
}

.apg-filter-btn {
    display: inline-block;
    padding: 8px 16px;
    margin: 4px;
    background: #fff;
    border: 1px solid #dbdbdb;
    border-radius: 8px;
    color: #262626;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.apg-filter-btn:hover {
    background: #f0f0f0;
    border-color: #b3b3b3;
}

.apg-filter-btn.active {
    background: #0095f6;
    color: #fff;
    border-color: #0095f6;
}

/* 網格容器 */
.apg-wrapper .apg-grid {
    -webkit-column-gap: 20px !important;
    -moz-column-gap: 20px !important;
    column-gap: 20px !important;
    margin-bottom: 30px;
    width: 100% !important;
    display: block !important;
}

/* 響應式欄位 */
.apg-wrapper .apg-grid.apg-columns-1 {
    -webkit-column-count: 1 !important;
    -moz-column-count: 1 !important;
    column-count: 1 !important;
}

.apg-wrapper .apg-grid.apg-columns-2 {
    -webkit-column-count: 2 !important;
    -moz-column-count: 2 !important;
    column-count: 2 !important;
}

.apg-wrapper .apg-grid.apg-columns-3 {
    -webkit-column-count: 3 !important;
    -moz-column-count: 3 !important;
    column-count: 3 !important;
}

.apg-wrapper .apg-grid.apg-columns-4 {
    -webkit-column-count: 4 !important;
    -moz-column-count: 4 !important;
    column-count: 4 !important;
}

.apg-wrapper .apg-grid.apg-columns-5 {
    -webkit-column-count: 5 !important;
    -moz-column-count: 5 !important;
    column-count: 5 !important;
}

.apg-wrapper .apg-grid.apg-columns-6 {
    -webkit-column-count: 6 !important;
    -moz-column-count: 6 !important;
    column-count: 6 !important;
}

/* 響應式設計 */
@media screen and (max-width: 1200px) {
    .apg-wrapper .apg-grid.apg-columns-5,
    .apg-wrapper .apg-grid.apg-columns-6 {
        -webkit-column-count: 4 !important;
        -moz-column-count: 4 !important;
        column-count: 4 !important;
    }
}

@media screen and (max-width: 992px) {
    .apg-wrapper .apg-grid.apg-columns-4,
    .apg-wrapper .apg-grid.apg-columns-5,
    .apg-wrapper .apg-grid.apg-columns-6 {
        -webkit-column-count: 3 !important;
        -moz-column-count: 3 !important;
        column-count: 3 !important;
    }
}

@media screen and (max-width: 768px) {
    .apg-wrapper .apg-grid.apg-columns-3,
    .apg-wrapper .apg-grid.apg-columns-4,
    .apg-wrapper .apg-grid.apg-columns-5,
    .apg-wrapper .apg-grid.apg-columns-6 {
        -webkit-column-count: 2 !important;
        -moz-column-count: 2 !important;
        column-count: 2 !important;
    }
}

@media screen and (max-width: 480px) {
    .apg-wrapper .apg-grid.apg-columns-2,
    .apg-wrapper .apg-grid.apg-columns-3,
    .apg-wrapper .apg-grid.apg-columns-4,
    .apg-wrapper .apg-grid.apg-columns-5,
    .apg-wrapper .apg-grid.apg-columns-6 {
        -webkit-column-count: 1 !important;
        -moz-column-count: 1 !important;
        column-count: 1 !important;
    }
}

/* Instagram Post 卡片 */
.apg-wrapper .apg-grid .apg-item {
    display: inline-block !important;
    width: 100% !important;
    margin-bottom: 28px;
    break-inside: avoid;
    page-break-inside: avoid;
    -webkit-column-break-inside: avoid;
    opacity: 1;
    transition: opacity 0.3s ease;
    vertical-align: top;
}

.apg-item.apg-hidden {
    display: none;
}

.apg-item-inner {
    background: #fff;
    border: 1px solid #dbdbdb;
    border-radius: 8px;
    overflow: hidden;
}

/* Instagram 頭部 */
.apg-post-header {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid #efefef;
}

.apg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
    margin-right: 12px;
    flex-shrink: 0;
}

.apg-user-info {
    flex: 1;
    min-width: 0;
}

.apg-username {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #262626;
    line-height: 18px;
}

.apg-time {
    display: block;
    font-size: 12px;
    color: #8e8e8e;
    line-height: 16px;
}

.apg-more-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: #262626;
    cursor: pointer;
    padding: 8px;
    line-height: 1;
    margin: -8px -8px -8px 0;
}

/* Instagram 圖片 */
.apg-post-image {
    position: relative;
    width: 100%;
    padding-bottom: 100%;
    overflow: hidden;
    background: #f5f5f5;
}

.apg-post-image a {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.apg-post-image img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Instagram 底部內容 */
.apg-post-content {
    padding: 0;
}

/* 操作按鈕行 */
.apg-action-buttons {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px 8px;
}

.apg-left-actions {
    display: flex;
    gap: 16px;
}

.apg-action-btn {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
}

.apg-action-btn svg {
    width: 24px;
    height: 24px;
    stroke: #262626;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.apg-action-btn:hover svg {
    stroke: #8e8e8e;
}

/* 內容描述區 */
.apg-post-description {
    padding: 0 16px 8px;
}

.apg-caption {
    font-size: 14px;
    line-height: 18px;
    color: #262626;
    margin-bottom: 4px;
}

.apg-caption-username {
    font-weight: 600;
    margin-right: 6px;
}

.apg-caption-text {
    font-weight: 400;
}

.apg-read-more {
    color: #8e8e8e;
    text-decoration: none;
    margin-left: 4px;
}

.apg-read-more:hover {
    color: #262626;
}

/* Hashtags */
.apg-hashtags {
    margin-top: 4px;
}

.apg-hashtag {
    color: #00376b;
    text-decoration: none;
    font-size: 14px;
    line-height: 18px;
    margin-right: 4px;
    font-weight: 400;
}

.apg-hashtag:hover {
    text-decoration: underline;
}

/* 時間戳記 */
.apg-post-time {
    padding: 0 16px 16px;
    font-size: 10px;
    color: #8e8e8e;
    letter-spacing: 0.2px;
    line-height: 12px;
}

/* 載入動畫 */
.apg-loading {
    text-align: center;
    padding: 40px 0;
}

.apg-spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #262626;
    border-radius: 50%;
    animation: apg-spin 0.8s linear infinite;
}

@keyframes apg-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 淡入動畫 */
.apg-item {
    animation: apg-fadeIn 0.4s ease;
}

@keyframes apg-fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 無內容狀態 */
.apg-no-posts {
    text-align: center;
    padding: 60px 20px;
    color: #8e8e8e;
    font-size: 16px;
}

/* Modal 覆蓋層 - FB 風格 */
.apg-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.apg-modal-overlay.active {
    opacity: 1;
}

/* Modal 容器 */
.apg-modal-container {
    position: relative;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 8px;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.apg-modal-overlay.active .apg-modal-container {
    transform: scale(1);
}

/* 關閉按鈕 */
.apg-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #262626;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.apg-modal-close:hover {
    background: #fff;
    transform: scale(1.1);
}

/* Modal 內容 */
.apg-modal-content {
    position: relative;
}

.apg-modal-content .apg-item-inner {
    border: none;
    border-radius: 0;
}

.apg-modal-content .apg-post-image {
    border-radius: 0;
}

/* 完整內容樣式 - FB Blog 風格 */
.apg-full-content {
    padding: 0 16px 16px;
}

.apg-full-text {
    font-size: 15px;
    line-height: 1.6;
    color: #1c1e21;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.apg-full-text p {
    margin: 0 0 16px;
}

.apg-full-text img {
    max-width: 100%;
    height: auto;
    margin: 16px 0;
    border-radius: 8px;
    display: block;
}

.apg-full-text h1,
.apg-full-text h2,
.apg-full-text h3 {
    font-weight: 600;
    margin: 24px 0 12px;
    line-height: 1.3;
    color: #050505;
}

.apg-full-text h1 {
    font-size: 24px;
}

.apg-full-text h2 {
    font-size: 20px;
}

.apg-full-text h3 {
    font-size: 17px;
}

.apg-full-text ul,
.apg-full-text ol {
    margin: 0 0 16px;
    padding-left: 24px;
}

.apg-full-text li {
    margin-bottom: 8px;
}

.apg-full-text a {
    color: #1877f2;
    text-decoration: none;
}

.apg-full-text a:hover {
    text-decoration: underline;
}

.apg-full-text blockquote {
    margin: 16px 0;
    padding: 12px 16px;
    border-left: 3px solid #e4e6eb;
    background: #f0f2f5;
    font-style: italic;
}

.apg-full-text code {
    background: #f0f2f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

.apg-full-text pre {
    background: #f0f2f5;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 16px 0;
}

.apg-full-text pre code {
    background: none;
    padding: 0;
}

/* 手機響應式 Modal */
@media screen and (max-width: 480px) {
    .apg-modal-overlay {
        padding: 0;
    }
    
    .apg-modal-container {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .apg-modal-close {
        top: 5px;
        right: 5px;
    }
}
