/* ConnectHub 前台樣式 */

/*
 * 尺寸系統（v1.4.0）：
 * 所有尺寸皆由 --ch-scale 縮放（1 = 100% = 預設）。
 * render_widget() 會把後台「小工具尺寸」設定以 inline style 打進 #connecthub-widget：
 *   style="--ch-scale: 1.4;"
 * 各斷點只覆寫「基準值」，縮放比例一路沿用，故手機版也等比例放大。
 */
#connecthub-widget {
    --ch-scale: 1;
    --ch-btn: calc(50px * var(--ch-scale));   /* 主按鈕直徑 */
    --ch-item: calc(45px * var(--ch-scale));  /* 管道/關閉按鈕直徑 */
    --ch-icon: calc(24px * var(--ch-scale));  /* 按鈕內圖示 */
    --ch-gap: calc(15px * var(--ch-scale));   /* 管道間距 */

    position: fixed;
    bottom: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
}

#connecthub-widget.connecthub-left {
    left: 20px;
}

#connecthub-widget.connecthub-right {
    right: 20px;
}

#connecthub-widget.connecthub-left-center {
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    bottom: auto;
}

#connecthub-widget.connecthub-right-center {
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    bottom: auto;
}

/* 主按鈕 */
.connecthub-widget-button {
    width: var(--ch-btn);
    height: var(--ch-btn);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    position: relative;
    order: 999;
}

.connecthub-widget-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

/* Hide main button when expanded */
.connecthub-widget.active .connecthub-widget-button {
    display: none;
}

.connecthub-widget-button:active {
    transform: translateY(0);
}

.connecthub-widget-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.connecthub-widget-button:hover::before {
    left: 100%;
}

.connecthub-cta-text {
    margin-right: 10px;
    white-space: nowrap;
}

.connecthub-widget-icon {
    display: flex;
    transition: transform 0.3s ease;
}

.connecthub-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 管道列表 */
.connecthub-channels-list {
    display: none;
    flex-direction: column;
    gap: var(--ch-gap);
    animation: connecthub-fadeIn 0.3s ease;
    margin-bottom: var(--ch-gap);
}

.connecthub-widget.active .connecthub-channels-list {
    display: flex;
}

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

/* 管道項目 */
.connecthub-channel-item {
    display: flex;
    align-items: center;
    justify-content: center;
}

.connecthub-channel-link,
.connecthub-close-button {
    width: var(--ch-item);
    height: var(--ch-item);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: white;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

.connecthub-channel-link:hover,
.connecthub-close-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    color: white;
    text-decoration: none;
}

.connecthub-channel-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
}

/* 所有按鈕內的 SVG 圖示（主按鈕加號、管道圖示、關閉叉）統一依 --ch-icon 縮放 */
.connecthub-channel-icon svg,
.connecthub-widget-button svg,
.connecthub-close-button svg {
    width: var(--ch-icon);
    height: var(--ch-icon);
    fill: white;
}

.connecthub-custom-channel-icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

/* 響應式設計：只覆寫各尺寸「基準值」，--ch-scale 一路沿用 → 手機版等比例縮放 */
@media (max-width: 768px) {
    #connecthub-widget {
        bottom: 15px;
        --ch-btn: calc(45px * var(--ch-scale));
        --ch-item: calc(40px * var(--ch-scale));
        --ch-icon: calc(20px * var(--ch-scale));
        --ch-gap: calc(12px * var(--ch-scale));
    }

    #connecthub-widget.connecthub-left {
        left: 15px;
    }

    #connecthub-widget.connecthub-right {
        right: 15px;
    }

    .connecthub-cta-text {
        margin-right: 8px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    #connecthub-widget {
        bottom: 10px;
        --ch-btn: calc(40px * var(--ch-scale));
        --ch-item: calc(35px * var(--ch-scale));
        --ch-icon: calc(18px * var(--ch-scale));
        --ch-gap: calc(10px * var(--ch-scale));
    }

    #connecthub-widget.connecthub-left {
        left: 10px;
    }

    #connecthub-widget.connecthub-right {
        right: 10px;
    }

    .connecthub-cta-text {
        font-size: 12px;
    }
}

/* 暗色主題支援 */
@media (prefers-color-scheme: dark) {
    .connecthub-channel-link {
        backdrop-filter: blur(10px) brightness(1.1);
    }
}

/* 高對比度支援 */
@media (prefers-contrast: high) {
    .connecthub-widget-button,
    .connecthub-channel-link {
        border: 2px solid rgba(255, 255, 255, 0.3);
    }
}

/* 減少動畫偏好 */
@media (prefers-reduced-motion: reduce) {
    .connecthub-widget-button,
    .connecthub-channel-link,
    .connecthub-channels-list,
    .connecthub-channel-item {
        transition: none;
        animation: none;
    }

    .connecthub-widget-button:hover,
    .connecthub-channel-link:hover {
        transform: none;
    }
}

/* 載入狀態 */
.connecthub-loading {
    opacity: 0.7;
    pointer-events: none;
}

.connecthub-loading .connecthub-widget-button {
    cursor: wait;
}

/* 錯誤狀態 */
.connecthub-error .connecthub-widget-button {
    background-color: #dc3545 !important;
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* 無障礙支援 */
.connecthub-widget-button:focus,
.connecthub-channel-link:focus {
    outline: 2px solid #4F6ACA;
    outline-offset: 2px;
}

/* Always Open Mode */
#connecthub-widget.always-open .connecthub-channels-list {
    display: flex;
}

#connecthub-widget.always-open .connecthub-widget-button,
#connecthub-widget.always-open .connecthub-close-button {
    display: none;
}
