/**
 * 浮動推薦文章 CSS
 * 將此檔案儲存為 floating-recommend.css 並放到主題目錄
 */

/* ==================== 主容器 ==================== */
#floating-recommend-container {
    position: fixed;
    z-index: 9999;
    background: var(--bg-color);
    border-radius: 12px;
    box-shadow: var(--shadow);
    max-height: 80vh;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

#floating-recommend-container.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

/* ==================== 位置設定 ==================== */
#floating-recommend-container.position-bottom-right {
    bottom: 20px;
    right: 20px;
}

#floating-recommend-container.position-bottom-left {
    bottom: 20px;
    left: 20px;
}

#floating-recommend-container.position-top-right {
    top: 20px;
    right: 20px;
}

#floating-recommend-container.position-top-left {
    top: 20px;
    left: 20px;
}

#floating-recommend-container.position-bottom-center {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
}

/* 往上滾動隱藏 */
#floating-recommend-container.hide-scroll {
    transform: translateY(100px);
    opacity: 0;
    pointer-events: none;
}

#floating-recommend-container.position-bottom-center.hide-scroll {
    transform: translate(-50%, 100px);
}

/* ==================== 主題模式 ==================== */
/* 淺色模式（默認） - 全白底 */
#floating-recommend-container {
    --bg-color: #ffffff;
    --text-color: #333333;
    --header-bg: #ffffff;
    --header-text: #333333;
    --border-color: #e0e0e0;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    --button-bg: rgba(0, 0, 0, 0.08);
    --button-hover-bg: rgba(0, 0, 0, 0.12);
    --button-text: #333333;
}

/* 深色模式 */
#floating-recommend-container.theme-dark {
    --bg-color: #1e1e1e;
    --text-color: #e0e0e0;
    --header-bg: linear-gradient(135deg, #2c3e50 0%, #1a252f 100%);
    --header-text: #ffffff;
    --border-color: #3a3a3a;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --button-bg: rgba(255, 255, 255, 0.15);
    --button-hover-bg: rgba(255, 255, 255, 0.25);
    --button-text: #ffffff;
}

/* ==================== 頭部 ==================== */
.floating-recommend-header {
    padding: 12px 16px;
    background: var(--header-bg);
    color: var(--header-text);
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    /*gap: 12px;*/
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid var(--border-color);
    cursor: move;
    min-height: 48px;
}

.floating-recommend-title-main {
    font-size: 16px;
    font-weight: 600;
    margin: 0px 20px 0px 0px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Icon is now handled via JS/PHP */
/*.floating-recommend-title-main::before {
    content: "⭐";
}*/


.floating-recommend-controls {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    flex-wrap: wrap;
    flex-shrink: 1;
    justify-content: flex-start;
}

.floating-recommend-btn {
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    color: var(--button-text);
    min-width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 13px;
    font-weight: 500;
    padding: 0 6px;
    white-space: nowrap;
}

.floating-recommend-btn:hover {
    background: var(--button-hover-bg);
    transform: translateY(-1px);
}

.floating-recommend-btn:active {
    transform: scale(0.95);
}

/* 按鈕文字樣式 */
.floating-recommend-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    width: auto;
    padding: 0 10px;
    transition: all 0.2s ease;
    flex-shrink: 0; /* Prevent buttons from shrinking */
    margin: 0; /* Remove any default margins */
}

.floating-recommend-btn .btn-icon {
    font-size: 16px;
    line-height: 1;
}

.floating-recommend-btn .btn-text {
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
}

/* 當沒有文字時，按鈕使用固定寬度 */
.floating-recommend-btn:not(:has(.btn-text)) {
    width: 32px;
    height: 32px;
    padding: 0;
    justify-content: center;
}

/* fallback for browsers that don't support :has() */
@supports not selector(:has(.btn-text)) {
    .floating-recommend-btn {
        min-width: 32px;
        min-height: 32px;
    }
}

/* 小螢幕時隱藏文字，只顯示圖標 */
@media (max-width: 768px) {
    .floating-recommend-btn .btn-text {
        display: none !important;
    }
    
    .floating-recommend-btn {
        width: 32px;
        height: 32px;
        padding: 0;
        min-width: unset;
    }
}

/* ==================== 關閉按鈕樣式 ==================== */
/* 絕對定位的關閉按鈕 */
.floating-recommend-close-absolute {
    position: absolute;
    z-index: 10;
    background: var(--button-bg);
    color: var(--button-text);
    border: 1px solid var(--border-color);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 16px;
    box-shadow: var(--shadow);
}

.floating-recommend-close-absolute:hover {
    background: var(--button-hover-bg);
    transform: scale(1.05);
}

/* 關閉按鈕形狀 */
#floating-recommend-container.close-button-circle .btn-close {
    border-radius: 50%;
}

#floating-recommend-container.close-button-square .btn-close {
    border-radius: 4px;
}

/* 關閉按鈕位置 - 需要絕對定位 */
#floating-recommend-container.close-button-pos-top-right .btn-close,
#floating-recommend-container.close-button-pos-top-left .btn-close,
#floating-recommend-container.close-button-pos-bottom-right .btn-close,
#floating-recommend-container.close-button-pos-bottom-left .btn-close {
    position: absolute;
    z-index: 10;
    background-color: rgba(0, 0, 0, 0.6); /* Dark background for visibility */
    color: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#floating-recommend-container.close-button-pos-top-right .btn-close:hover,
#floating-recommend-container.close-button-pos-top-left .btn-close:hover,
#floating-recommend-container.close-button-pos-bottom-right .btn-close:hover,
#floating-recommend-container.close-button-pos-bottom-left .btn-close:hover {
    background-color: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

/* 右上角 */
#floating-recommend-container.close-button-pos-top-right .btn-close {
    top: 10px;
    right: 10px;
}

/* 左上角 */
#floating-recommend-container.close-button-pos-top-left .btn-close {
    top: 10px;
    left: 10px;
}

/* 右下角 */
#floating-recommend-container.close-button-pos-bottom-right .btn-close {
    bottom: 10px;
    right: 10px;
}

/* 左下角 */
#floating-recommend-container.close-button-pos-bottom-left .btn-close {
    bottom: 10px;
    left: 10px;
}

/* 關閉按鈕位置 - 調整以避免與頭部按鈕重疊 */
.close-button-pos-top-right .floating-recommend-close-absolute {
    top: -12px;
    right: -12px;
}

/* 左上角 */
#floating-recommend-container.close-button-pos-top-left .floating-recommend-close-absolute {
    top: -12px;
    left: -12px;
}

/* 右下角 */
#floating-recommend-container.close-button-pos-bottom-right .floating-recommend-close-absolute {
    bottom: -12px;
    right: -12px;
}

/* 左下角 */
#floating-recommend-container.close-button-pos-bottom-left .floating-recommend-close-absolute {
    bottom: -12px;
    left: -12px;
}


/* 當關閉按鈕絕對定位時，從控制列中隱藏 */
#floating-recommend-container.close-button-pos-top-right .floating-recommend-controls .btn-close,
#floating-recommend-container.close-button-pos-top-left .floating-recommend-controls .btn-close,
#floating-recommend-container.close-button-pos-bottom-right .floating-recommend-controls .btn-close,
#floating-recommend-container.close-button-pos-bottom-left .floating-recommend-controls .btn-close {
    display: none;
}

/* ==================== 內容區域 ==================== */
.floating-recommend-content-wrapper {
    max-height: calc(80vh - 100px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: var(--bg-color);
}

.floating-recommend-content-wrapper::-webkit-scrollbar {
    width: 6px;
}

.floating-recommend-content-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.floating-recommend-content-wrapper::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.floating-recommend-content-wrapper::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ==================== 載入狀態 ==================== */
.floating-recommend-loading {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.floating-recommend-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--theme-color, #0073aa);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

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

/* ==================== 文章列表 ==================== */
.floating-recommend-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.floating-recommend-list a{
    text-decoration: none;
}
/* ==================== 文章項目 ==================== */
.floating-recommend-item {
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s;
    background: #fff;
    border: 1px solid #e5e7eb;
}

.floating-recommend-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
    border-color: var(--theme-color, #0073aa);
}

.floating-recommend-link {
    display: flex;
    text-decoration: none;
    color: inherit;
}

/* ==================== 布局：左圖右文 ==================== */
.floating-recommend-item.layout-left-image .floating-recommend-link {
    flex-direction: row;
}

.floating-recommend-item.layout-left-image .floating-recommend-image {
    width: 120px;
    min-width: 120px;
    height: 120px;
}

.floating-recommend-item.layout-left-image .floating-recommend-content {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* ==================== 布局：右圖左文 ==================== */
.floating-recommend-item.layout-right-image .floating-recommend-link {
    flex-direction: row-reverse;
}

.floating-recommend-item.layout-right-image .floating-recommend-image {
    width: 120px;
    min-width: 120px;
    height: 120px;
}

.floating-recommend-item.layout-right-image .floating-recommend-content {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* ==================== 布局：上圖下文 ==================== */
.floating-recommend-item.layout-top-image .floating-recommend-link {
    flex-direction: column;
}

.floating-recommend-item.layout-top-image .floating-recommend-image {
    width: 100%;
    height: 180px;
}

.floating-recommend-item.layout-top-image .floating-recommend-content {
    padding: 12px;
}

/* ==================== 布局：下圖上文 ==================== */
.floating-recommend-item.layout-bottom-image .floating-recommend-link {
    flex-direction: column-reverse;
}

.floating-recommend-item.layout-bottom-image .floating-recommend-image {
    width: 100%;
    height: 180px;
}

.floating-recommend-item.layout-bottom-image .floating-recommend-content {
    padding: 12px;
}

/* ==================== 圖片 ==================== */
.floating-recommend-image {
    position: relative;
    overflow: hidden;
    background: #f3f4f6;
}

.floating-recommend-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.floating-recommend-item:hover .floating-recommend-thumb {
    transform: scale(1.05);
}

/* ==================== 文字內容 ==================== */
.floating-recommend-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.5;           /* 設定行高，讓閱讀更舒適 */
    margin: 0 0 8px 0;
    color: #1f2937;
    
    /* === 限制 3 行並顯示刪節號 === */
    display: -webkit-box;       /* 必須 */
    -webkit-line-clamp: 3;      /* 限制行數為 3 */
    -webkit-box-orient: vertical; /* 排列方向 */
    overflow: hidden;           /* 隱藏超出範圍的文字 */
    text-overflow: ellipsis;    /* 確保出現刪節號 */
    max-height: 4.5em;          /* (1.5行高 * 3行) 避免舊瀏覽器破版 */
}

.floating-recommend-excerpt {
    font-size: 12px;
    line-height: 1.5;           /* 設定行高 */
    color: #6b7280;
    margin: 0 0 8px 0;
    
    /* === 限制 3 行並顯示刪節號 === */
    display: -webkit-box;       /* 必須 */
    -webkit-line-clamp: 3;      /* 限制行數為 3 */
    -webkit-box-orient: vertical; /* 排列方向 */
    overflow: hidden;           /* 隱藏超出範圍的文字 */
    text-overflow: ellipsis;    /* 確保出現刪節號 */
}
.floating-recommend-excerpt {
    font-size: 13px;
    color: var(--text-color);
    opacity: 0.8;
    margin-bottom: 8px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: var(--excerpt-lines, 3);
    -webkit-box-orient: vertical;
    overflow: hidden;
}
/* ==================== 元資訊 ==================== */
.floating-recommend-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 11px;
    color: #9ca3af;
}

.floating-recommend-category {
    background: var(--theme-color, #0073aa);
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
}

.floating-recommend-date,
.floating-recommend-views {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ==================== 廣告區域 ==================== */
.floating-recommend-ad {
    margin: 12px 0;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px dashed #d1d5db;
    text-align: center;
}

/* ==================== 分頁指示器 ==================== */
.floating-recommend-pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 12px 0;
}

.floating-recommend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d1d5db;
    cursor: pointer;
    transition: all 0.3s;
}

.floating-recommend-dot:hover {
    background: #9ca3af;
}

.floating-recommend-dot.active {
    background: var(--theme-color, #0073aa);
    width: 24px;
    border-radius: 4px;
}

/* ==================== 最小化狀態 ==================== */
#floating-recommend-container.minimized {
    width: 60px !important;
    height: 60px;
    overflow: visible;
}

/* 1. 修改 Header：讓內部圖示置中 */
#floating-recommend-container.minimized .floating-recommend-header {
    padding: 0;              /* 清除內距 */
    border-radius: 50%;      /* 保持圓形 */
    display: flex;           /* 使用 Flex 排版 */
    align-items: center;     /* 垂直置中 */
    justify-content: center; /* 水平置中 */
    width: 100%;
    height: 100%;
    cursor: pointer;         /* 顯示可點擊手勢 */
}

/* 2. 新增：最小化時顯示「放大/還原」圖示 */
#floating-recommend-container.minimized .floating-recommend-header::after {
    content: "";            /* 清空文字 */
    display: block;
    width: 24px;            /* 設定圖示寬度 */
    height: 24px;           /* 設定圖示高度 */
    /* 使用 SVG 雙向箭頭作為背景圖 */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23555555' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.7;           /* 稍微透明一點，不要太死黑 */
}

/* 如果是深色模式，要讓箭頭變白 */
#floating-recommend-container.theme-dark.minimized .floating-recommend-header::after {
    filter: invert(1);      /* 反轉顏色變白 */
}

/* 3. 隱藏原本的標題與按鈕 (保持不變) */
#floating-recommend-container.minimized .floating-recommend-title-main {
    display: none !important;
}

#floating-recommend-container.minimized .floating-recommend-content-wrapper,
#floating-recommend-container.minimized .floating-recommend-pagination {
    display: none;
}

#floating-recommend-container.minimized .btn-minimize,
#floating-recommend-container.minimized .btn-prev,
#floating-recommend-container.minimized .btn-next,
#floating-recommend-container.minimized .btn-close {
    display: none;
}

/* 確保絕對定位的關閉按鈕也被隱藏 */
#floating-recommend-container.minimized .floating-recommend-close-absolute {
    display: none;
}

/* 縮小時只顯示一個恢復按鈕（點擊header恢復） */
#floating-recommend-container.minimized .floating-recommend-header {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==================== 響應式設計 ==================== */
@media (max-width: 768px) {
    #floating-recommend-container {
        max-width: calc(100% - 40px);
    }
    
    .floating-recommend-item.layout-left-image .floating-recommend-image,
    .floating-recommend-item.layout-right-image .floating-recommend-image {
        width: 100px;
        min-width: 100px;
        height: 100px;
    }
    
    .floating-recommend-title {
        font-size: 13px;
    }
    
    .floating-recommend-excerpt {
        font-size: 11px;
    }
    
    .floating-recommend-header {
        padding: 12px 16px;
    }
    
    .floating-recommend-title-main {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    #floating-recommend-container.position-bottom-right,
    #floating-recommend-container.position-bottom-left {
        bottom: 10px;
        right: 10px;
        left: 10px;
    }
    
    #floating-recommend-container.position-top-right,
    #floating-recommend-container.position-top-left {
        top: 10px;
        right: 10px;
        left: 10px;
    }
    
    .floating-recommend-item.layout-left-image .floating-recommend-link,
    .floating-recommend-item.layout-right-image .floating-recommend-link {
        flex-direction: column;
    }
    
    .floating-recommend-item.layout-left-image .floating-recommend-image,
    .floating-recommend-item.layout-right-image .floating-recommend-image {
        width: 100%;
        height: 150px;
    }
    
    .floating-recommend-controls {
        gap: 4px;
    }
    
    .floating-recommend-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
}

/* ==================== 深色模式樣式 ==================== */
#floating-recommend-container.theme-dark .floating-recommend-item {
    background: #1f2937;
    border-color: #374151;
}

#floating-recommend-container.theme-dark .floating-recommend-title {
    color: #f9fafb;
}

#floating-recommend-container.theme-dark .floating-recommend-excerpt {
    color: #d1d5db;
}

#floating-recommend-container.theme-dark .floating-recommend-meta {
    color: #9ca3af;
}

#floating-recommend-container.theme-dark .floating-recommend-ad {
    background: #111827;
    border-color: #374151;
}

#floating-recommend-container.theme-dark .floating-recommend-content-wrapper::-webkit-scrollbar-track {
    background: #374151;
}

#floating-recommend-container.theme-dark .floating-recommend-content-wrapper::-webkit-scrollbar-thumb {
    background: #6b7280;
}

/* ==================== 動畫效果 ==================== */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

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

.floating-recommend-item {
    animation: fadeIn 0.3s ease-out;
}

/* ==================== 打印時隱藏 ==================== */
@media print {
    #floating-recommend-container {
        display: none !important;
    }
}

/* ==================== 無障礙輔助 ==================== */
.floating-recommend-btn:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.floating-recommend-link:focus {
    outline: 2px solid var(--theme-color, #0073aa);
    outline-offset: 2px;
}

/* ==================== 載入動畫優化 ==================== */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.floating-recommend-loading p {
    animation: pulse 1.5s ease-in-out infinite;
}

/* ==================== 滑動效果 ==================== */
.floating-recommend-content-wrapper {
    scroll-behavior: smooth;
}

/* ==================== 高對比度模式 ==================== */
@media (prefers-contrast: high) {
    #floating-recommend-container {
        border: 2px solid #000;
    }
    
    .floating-recommend-item {
        border-width: 2px;
    }
    
    .floating-recommend-btn {
        border: 1px solid #fff;
    }
}

/* ==================== 推薦標籤 ==================== */
.floating-recommend-label {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
}

/* 圖片上的絕對定位標籤 */
.floating-recommend-label-overlay {
    position: absolute;
    z-index: 5;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.floating-recommend-label-overlay.pos-top-left {
    top: 6px;
    left: 6px;
}

.floating-recommend-label-overlay.pos-top-right {
    top: 6px;
    right: 6px;
}

.floating-recommend-label-overlay.pos-bottom-left {
    bottom: 6px;
    left: 6px;
}

.floating-recommend-label-overlay.pos-bottom-right {
    bottom: 6px;
    right: 6px;
}