/**
 * accessibility.css
 * 可存取性和轉換率優化樣式
 * 所有顏色使用 design-tokens.css 定義的 CSS Variables
 */

/* ==================== Focus 可見性 ==================== */
/* 鍵盤焦點指示器 - WCAG 2.1 要求 */
:focus-visible {
    outline: 3px solid var(--color-info) !important;
    outline-offset: 2px !important;
}

/* 滑鼠焦點不顯示 outline */
:focus:not(:focus-visible) {
    outline: none;
}

/* 按鈕和連結的焦點狀態 */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--color-info);
    outline-offset: var(--space-0-5);
    box-shadow: 0 0 0 var(--space-1) rgba(37, 99, 235, 0.2);
}

/* ==================== 顏色對比修正 ==================== */
/* WCAG AA 要求最小對比度 4.5:1 */
.text-muted {
    color: var(--color-gray-600) !important;
}

.text-light {
    color: var(--color-text-secondary) !important;
}

/* 價格顏色對比 */
.price-sale {
    color: var(--color-brand-accent) !important;
    font-weight: 600;
}

.price-original {
    color: var(--color-text-secondary);
    text-decoration: line-through;
}

/* ==================== 觸控目標尺寸 ==================== */
/* WCAG 2.1 要求最小 44x44px */
.touch-target {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* 數量調整按鈕 */
.qty-control button {
    min-width: 44px;
    min-height: 44px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qty-control input {
    min-height: 44px;
    text-align: center;
    font-size: 1rem;
}

/* ==================== 螢幕閱讀器專用 ==================== */
.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;
}

.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ==================== 表單驗證回饋 ==================== */
.form-group {
    position: relative;
}

.form-group .error-message {
    display: none;
    color: var(--color-brand-accent);
    font-size: var(--font-size-xs);
    margin-top: var(--space-1);
    padding: var(--space-1) var(--space-2-5);
    background: var(--color-brand-accent-light);
    border-left: 3px solid var(--color-brand-accent);
}

.form-group.has-error .error-message {
    display: block;
}

.form-group.has-error input,
.form-group.has-error select,
.form-group.has-error textarea {
    border-color: var(--color-brand-accent);
    background: var(--color-brand-accent-light);
}

.form-group.has-success input,
.form-group.has-success select,
.form-group.has-success textarea {
    border-color: var(--color-success);
}

/* 必填欄位標示 */
.required-mark {
    color: var(--color-brand-accent);
    font-weight: bold;
}

/* ==================== 庫存警示 ==================== */
.stock-warning {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1-5) var(--space-3);
    background: var(--color-warning-light);
    color: var(--color-warning-hover);
    border-radius: var(--radius-DEFAULT);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    animation: pulse 2s infinite;
}

.stock-warning i {
    color: var(--color-warning);
}

.stock-critical {
    background: var(--color-error-light);
    color: var(--color-error-hover);
}

.stock-critical i {
    color: var(--color-brand-accent);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ==================== CTA 按鈕層級 ==================== */
/* 主要 CTA - 立即購買 */
.btn-primary-cta {
    background: var(--color-brand-accent) !important;
    border-color: var(--color-brand-accent) !important;
    color: var(--color-white) !important;
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wide);
    padding: var(--space-3-5) var(--space-8);
    font-size: var(--font-size-base);
    transition: var(--transition-all);
    box-shadow: var(--shadow-md);
}

.btn-primary-cta:hover {
    background: var(--color-brand-accent-hover) !important;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* 次要 CTA - 加入購物車 */
.btn-secondary-cta {
    background: var(--color-gray-800) !important;
    border-color: var(--color-gray-800) !important;
    color: var(--color-white) !important;
    padding: var(--space-3-5) var(--space-8);
    font-size: var(--font-size-base);
}

.btn-secondary-cta:hover {
    background: var(--color-gray-700) !important;
}

/* ==================== 免運進度條優化 ==================== */
.shipping-progress {
    background: var(--color-gray-100);
    border-radius: var(--radius-full);
    height: var(--space-2);
    overflow: hidden;
    position: relative;
}

.shipping-progress__fill {
    background: linear-gradient(90deg, var(--color-success), var(--color-success-hover));
    height: 100%;
    border-radius: var(--radius-full);
    transition: width var(--duration-500) var(--ease-out);
}

.shipping-progress__text {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--space-2);
    font-size: var(--font-size-sm);
}

.shipping-progress__amount {
    font-weight: 600;
    color: var(--color-success);
}

.shipping-progress--complete .shipping-progress__fill {
    background: linear-gradient(90deg, var(--color-success), var(--color-success-light));
}

/* ==================== 信任標章 ==================== */
.trust-badges-checkout {
    display: flex;
    justify-content: center;
    gap: var(--space-5);
    padding: var(--space-4);
    background: var(--color-success-bg);
    border: 1px solid var(--color-success-light);
    border-radius: var(--radius-lg);
    margin: var(--space-5) 0;
}

.trust-badge-small {
    display: flex;
    align-items: center;
    gap: var(--space-1-5);
    font-size: var(--font-size-xs);
    color: var(--color-success-hover);
}

.trust-badge-small i {
    font-size: var(--font-size-base);
    color: var(--color-success);
}

/* ==================== 到貨時間 ==================== */
.delivery-estimate {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background: var(--color-info-bg);
    border-radius: var(--radius-md);
    margin: var(--space-4) 0;
    font-size: var(--font-size-sm);
}

.delivery-estimate i {
    color: var(--color-info);
    font-size: var(--font-size-lg);
}

.delivery-estimate strong {
    color: var(--color-info-hover);
}

/* ==================== 客服浮動按鈕 ==================== */
.customer-service-fab {
    position: fixed;
    bottom: var(--space-8);
    right: var(--space-8);
    z-index: var(--z-fixed);
}

.cs-fab-btn {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-full);
    background: linear-gradient(
        160deg,
        #c0c0c0 0%,
        #f8f8f8 20%,
        #a0a0a0 40%,
        #e0e0e0 60%,
        #909090 80%,
        #d0d0d0 100%
    );
    color: #222;
    border: 1px solid #777;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-2xl);
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.35),
        0 0 20px rgba(255, 255, 255, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.7);
    transition: var(--transition-all);
    position: relative;
    overflow: hidden;
}

.cs-fab-btn::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent 40%,
        rgba(255, 255, 255, 0.4) 50%,
        transparent 60%
    );
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.cs-fab-btn:hover::before {
    transform: translateX(100%);
}

.cs-fab-btn:hover {
    transform: translateY(-2px);
    box-shadow:
        0 6px 12px rgba(0, 0, 0, 0.4),
        0 0 30px rgba(255, 255, 255, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

/* FAB 自訂圖片模式：透明背景，圖片即按鈕 */
.cs-fab-btn:has(.cs-fab-custom-icon) {
    background: transparent;
    box-shadow: none;
    border: none;
}

.cs-fab-btn:has(.cs-fab-custom-icon)::before {
    display: none;
}

.cs-fab-btn:has(.cs-fab-custom-icon):hover {
    background: transparent;
    box-shadow: none;
    transform: scale(1.05);
}

.cs-fab-custom-icon {
    width: 60px;
    height: 60px;
    object-fit: contain;
    border-radius: 0;
    transition: var(--transition-all);
}

.cs-fab-btn:hover .cs-fab-custom-icon {
    filter: brightness(1.1);
}

.cs-fab-tooltip {
    position: absolute;
    right: 70px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--color-gray-800);
    color: var(--color-white);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-all);
}

.customer-service-fab:hover .cs-fab-tooltip {
    opacity: 1;
    visibility: visible;
}

/* ==================== 通知系統優化 ==================== */
.toast-notification {
    position: fixed;
    bottom: var(--space-8);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--color-gray-800);
    color: var(--color-white);
    padding: var(--space-4) var(--space-6);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    z-index: var(--z-toast);
    opacity: 0;
    transition: var(--transition-all);
    max-width: 90%;
}

.toast-notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-notification.toast-success {
    background: var(--color-success-hover);
}

.toast-notification.toast-error {
    background: var(--color-error-hover);
}

.toast-notification i {
    font-size: var(--font-size-xl);
}

.toast-close {
    background: none;
    border: none;
    color: var(--color-white);
    opacity: 0.7;
    cursor: pointer;
    padding: var(--space-1);
    margin-left: var(--space-2-5);
}

.toast-close:hover {
    opacity: 1;
}

/* ==================== 高對比模式支持 ==================== */
@media (prefers-contrast: more) {
    .text-muted {
        color: var(--color-gray-700) !important;
    }

    :focus-visible {
        outline-width: 4px !important;
    }

    .btn {
        border-width: 2px;
    }
}

/* ==================== 減少動畫模式 ==================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================== 響應式觸控優化 ==================== */
@media (max-width: 768px) {
    /* 確保所有可點擊元素都夠大 (WCAG 44px) */
    .btn,
    button,
    a.nav-links,
    .product-card {
        min-height: 44px;
    }

    /* 表單元素間距 */
    .form-group {
        margin-bottom: var(--space-6);
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: var(--space-3-5);
        font-size: 16px; /* 防止 iOS 縮放 */
    }

    /* 結帳頁優化 */
    .trust-badges-checkout {
        flex-direction: column;
        gap: var(--space-2-5);
    }

    /* 客服按鈕位置調整 */
    .customer-service-fab {
        bottom: var(--space-5);
        right: var(--space-5);
    }

    .cs-fab-btn {
        width: 55px;
        height: 55px;
    }

    .cs-fab-custom-icon {
        width: 55px;
        height: 55px;
    }
}
