/* ══════════════════════════════════════════════════════════════
   Toast 通知樣式
   配合 colors.css CSS 變數實現自動淺/深色模式切換
   ══════════════════════════════════════════════════════════════ */

/* ══ 容器 ══ */
.toast-container-slide {
    z-index: 9999;
    pointer-events: none;
}

/* ══ 基礎 Toast ══ */
.toast-slide {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-light);
    border-left: 4px solid transparent;
    margin-bottom: 10px;
    overflow: hidden;
    transform: translateX(110%);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
                opacity 0.35s ease,
                border-radius 0.25s ease,
                max-width 0.25s ease;
    opacity: 0;
    position: relative;
    max-width: 300px;
    pointer-events: auto;
    touch-action: pan-x;
}

.toast-slide.slide-in {
    transform: translateX(0);
    opacity: 1;
}

.toast-slide.slide-out {
    transform: translateX(110%);
    opacity: 0;
    transition-duration: 0.25s;
}

/* ══ 緊湊視圖 ══ */
.toast-slide-compact {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    cursor: default;
    transition: background-color 0.15s ease;
    user-select: none;
}

/* ══ 圖示（圓形底色）══ */
.toast-slide-icon {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    border-radius: 50%;
}

/* ══ 內容 ══ */
.toast-slide-content {
    flex: 1;
    min-width: 0;
}

.toast-slide-title {
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 1px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toast-slide-message {
    line-height: 1.4;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: break-word;
}

/* ══ 緊湊區操作按鈕 ══ */
.toast-slide-actions {
    display: flex;
    flex-shrink: 0;
    gap: 2px;
    margin-left: 8px;
}

.toast-slide-close {
    width: 26px;
    height: 26px;
    border: none;
    background: none;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    color: var(--text-light);
    flex-shrink: 0;
}

.toast-slide-close:hover {
    background-color: rgba(var(--danger-color-rgb), 0.12);
    color: rgb(var(--danger-color-rgb));
}

/* ══ 展開視圖（Hover / 點擊觸發）══ */
.toast-slide-expanded {
    display: none;
    padding: 14px;
    border-top: 1px solid var(--border-light);
    background-color: var(--bg-secondary);
}

.toast-slide.expanded .toast-slide-compact {
    border-bottom: 1px solid var(--border-light);
}

.toast-slide.expanded .toast-slide-expanded {
    display: block;
    animation: expandDown 0.2s ease-out;
}

.toast-slide-expanded-content {
    margin-bottom: 10px;
}

.toast-slide-expanded-title {
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.toast-slide-expanded-message {
    line-height: 1.6;
    color: var(--text-secondary);
    word-break: break-word;
    white-space: pre-wrap;
}

/* ══ 展開區操作列（複製 + 關閉）══ */
.toast-slide-expanded-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

/* 複製按鈕 */
.toast-copy-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1;
}

.toast-copy-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--text-light);
}

.toast-copy-btn.copied {
    color: rgb(var(--success-color-rgb));
    border-color: rgba(var(--success-color-rgb), 0.4);
    background: rgba(var(--success-color-rgb), 0.08);
}

/* 展開區的關閉按鈕 */
.toast-expanded-close-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: none;
    background: none;
    border-radius: 6px;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1;
}

.toast-expanded-close-btn:hover {
    background: rgba(var(--danger-color-rgb), 0.12);
    color: rgb(var(--danger-color-rgb));
}

/* ══ 進度條 ══ */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    width: 100%;
    transform-origin: left;
    animation-name: toastProgress;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
    animation-play-state: paused; /* JS 啟動後才開始 */
    border-radius: 0 0 0 8px;
}

@keyframes toastProgress {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

/* ══════════════════════════════════════
   TYPE: SUCCESS → 小藥丸 (Pill)
   ══════════════════════════════════════ */
.toast-slide-success {
    border-left-color: rgb(var(--success-color-rgb));
}

.toast-slide-success.expanded {
    max-width: 300px;
}

.toast-slide-success .toast-slide-icon {
    background: rgba(var(--success-color-rgb), 0.12);
    color: rgb(var(--success-color-rgb));
}

.toast-slide-success .toast-progress {
    background: rgb(var(--success-color-rgb));
}

/* ══════════════════════════════════════
   TYPE: ERROR → 紅色左框
   ══════════════════════════════════════ */
.toast-slide-error {
    border-left-color: rgb(var(--danger-color-rgb));
}

.toast-slide-error .toast-slide-icon {
    background: rgba(var(--danger-color-rgb), 0.12);
    color: rgb(var(--danger-color-rgb));
}

.toast-slide-error .toast-progress {
    background: rgb(var(--danger-color-rgb));
}

/* ══════════════════════════════════════
   TYPE: WARNING → 橘色左框
   ══════════════════════════════════════ */
.toast-slide-warning {
    border-left-color: rgb(var(--warning-color-rgb));
}

.toast-slide-warning .toast-slide-icon {
    background: rgba(var(--warning-color-rgb), 0.12);
    color: rgb(var(--warning-color-rgb));
}

.toast-slide-warning .toast-progress {
    background: rgb(var(--warning-color-rgb));
}

/* ══════════════════════════════════════
   TYPE: INFO → 藍色左框
   ══════════════════════════════════════ */
.toast-slide-info {
    border-left-color: rgb(var(--primary-blue-rgb));
}

.toast-slide-info .toast-slide-icon {
    background: rgba(var(--primary-blue-rgb), 0.12);
    color: rgb(var(--primary-blue-rgb));
}

.toast-slide-info .toast-progress {
    background: rgb(var(--primary-blue-rgb));
}

/* ══════════════════════════════════════
   深色模式覆寫
   大部分顏色由 CSS 變數 + RGB 變數自動處理，
   僅覆寫變數無法處理的項目
   ══════════════════════════════════════ */

/* 基礎 toast：深色模式使用較亮背景層，與頁面背景(--bg-secondary)區隔 */
[data-bs-theme=dark] .toast-slide {
    background: var(--bg-tertiary);
    /* 只覆寫上/右/下邊框色，保留 border-left 給各 type 設定 */
    border-top-color: var(--border-color);
    border-right-color: var(--border-color);
    border-bottom-color: var(--border-color);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* Success：深色模式無需額外覆寫，CSS 變數自動處理 */

/* ══ 響應式 ══ */
@media (max-width: 768px) {
    .toast-container-slide {
        bottom: 20px !important;
        top: auto !important;
        right: 10px !important;
        left: 10px !important;
        transform: none !important;
        width: auto !important;
        max-width: calc(100vw - 20px) !important;
    }

    .toast-slide {
        max-width: none;
        width: 100%;
    }

    .toast-slide-success {
        max-width: none;
    }

    .toast-slide-compact {
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    .toast-container-slide {
        bottom: 15px !important;
        right: 8px !important;
        left: 8px !important;
        max-width: calc(100vw - 16px) !important;
    }

    .toast-slide-icon {
        width: 26px;
        height: 26px;
    }
}

/* 行動裝置：點擊展開，加上 pointer 提示 */
@media (hover: none) {
    .toast-slide-compact {
        cursor: pointer;
    }
}

/* ══ 動畫 ══ */
@keyframes expandDown {
    from { opacity: 0; max-height: 0; }
    to   { opacity: 1; max-height: 400px; }
}

/* ══ 無障礙：減少動效 ══ */
@media (prefers-reduced-motion: reduce) {
    .toast-slide {
        transition: opacity 0.2s ease;
        transform: none !important;
    }

    .toast-slide.slide-out {
        opacity: 0;
    }
}

/* ══ 高對比模式 ══ */
@media (prefers-contrast: high) {
    .toast-slide {
        border: 2px solid currentColor;
        box-shadow: none;
    }

    .toast-slide-success {
        border-radius: 8px;
    }
}
