/**
 * YS CART — 共用樣式
 *
 * Morandi 色系前端設計，柔和低飽和度配色。
 *
 * @version 2.0.0
 */

/* ======================================================
 * Morandi 前端 CSS 變數
 * ====================================================== */

:root {
    /* 主色系 — Morandi 暖灰藍 */
    --ys-ec-primary: #7a9bae;
    --ys-ec-primary-dark: #5a7d91;
    --ys-ec-primary-light: #a8c2d0;
    --ys-ec-primary-bg: #edf3f7;
    --ys-ec-secondary: #8d9aa5;
    --ys-ec-success: #6ea383;
    --ys-ec-success-light: #e4f0e8;
    --ys-ec-success-bg: #e8f3ec;
    --ys-ec-success-text: #3a6548;
    --ys-ec-danger: #bf7878;
    --ys-ec-danger-light: #f5e4e4;
    --ys-ec-danger-bg: #f8e8e8;
    --ys-ec-danger-text: #8b4c4c;
    --ys-ec-warning: #c0a06e;
    --ys-ec-warning-light: #f4ede0;
    --ys-ec-warning-bg: #faf2e5;
    --ys-ec-warning-text: #7a6530;
    --ys-ec-info-bg: #edf3f7;

    /* 中性色 */
    --ys-ec-body-bg: #f6f5f2;
    --ys-ec-card-bg: #ffffff;
    --ys-ec-border: #d4dbe2;
    --ys-ec-border-light: #e5eaef;
    --ys-ec-text: #2d3a45;
    --ys-ec-text-muted: #6e7f8d;
    --ys-ec-text-light: #98a7b3;
    --ys-ec-placeholder: #b0bcc6;

    /* 圓角與陰影 */
    --ys-ec-radius: 8px;
    --ys-ec-radius-lg: 12px;
    --ys-ec-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.03);
    --ys-ec-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08);
    --ys-ec-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);

    /* 字型 */
    --ys-ec-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;

    /* 過渡動畫 */
    --ys-ec-transition: 0.2s ease;
    --ys-ec-transition-slow: 0.3s ease;
}

/* ======================================================
 * 基礎排版
 * ====================================================== */

.ys-ec-auth-overlay,
.ys-ec-auth-modal,
.ys-ec-cart-page,
.ys-ec-checkout-wrapper,
.ys-ec-dashboard-wrapper,
.ys-ec-product-list,
.ys-ec-product-detail {
    font-family: var(--ys-ec-font);
    color: var(--ys-ec-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 連結全域樣式 */
.ys-ec-auth-modal a,
.ys-ec-cart-page a,
.ys-ec-checkout-wrapper a,
.ys-ec-dashboard-wrapper a,
.ys-ec-product-list a,
.ys-ec-product-detail a {
    color: var(--ys-ec-primary-dark);
    transition: color var(--ys-ec-transition);
}

.ys-ec-auth-modal a:hover,
.ys-ec-cart-page a:hover,
.ys-ec-checkout-wrapper a:hover,
.ys-ec-dashboard-wrapper a:hover,
.ys-ec-product-list a:hover,
.ys-ec-product-detail a:hover {
    color: var(--ys-ec-primary);
}

/* 全域 focus 環 */
.ys-ec-auth-modal *:focus-visible,
.ys-ec-cart-page *:focus-visible,
.ys-ec-checkout-wrapper *:focus-visible,
.ys-ec-dashboard-wrapper *:focus-visible,
.ys-ec-product-list *:focus-visible,
.ys-ec-product-detail *:focus-visible {
    outline: 2px solid var(--ys-ec-primary);
    outline-offset: 2px;
}

/* ======================================================
 * 登入/註冊 Modal 樣式
 * ====================================================== */

/* --- Overlay 遮罩（毛玻璃效果） --- */
.ys-ec-auth-overlay {
    position: fixed;
    inset: 0;
    background: rgba(44, 62, 80, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: ysEcFadeIn 0.25s ease;
}

@keyframes ysEcFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* --- Modal 主體 --- */
.ys-ec-auth-modal {
    position: relative;
    background: var(--ys-ec-card-bg);
    border-radius: var(--ys-ec-radius-lg);
    box-shadow: 0 20px 60px rgba(44, 62, 80, 0.2);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 36px;
    animation: ysEcSlideDown 0.3s ease;
}

@keyframes ysEcSlideDown {
    from { opacity: 0; transform: translateY(-20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- 關閉按鈕 --- */
.ys-ec-auth-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: none;
    background: var(--ys-ec-primary-bg);
    border-radius: 50%;
    font-size: 20px;
    line-height: 1;
    color: var(--ys-ec-text-muted);
    cursor: pointer;
    transition: background var(--ys-ec-transition), color var(--ys-ec-transition), box-shadow var(--ys-ec-transition);
    padding: 0;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.ys-ec-auth-close:hover {
    background: var(--ys-ec-primary-light);
    color: var(--ys-ec-text);
}

/* --- Tab 切換（平滑底線） --- */
.ys-ec-auth-tabs {
    display: flex;
    border-bottom: 2px solid var(--ys-ec-border);
    margin-bottom: 28px;
    gap: 0;
}

.ys-ec-auth-tab {
    flex: 1;
    padding: 14px 0;
    border: none;
    background: none;
    font-size: 15px;
    font-weight: 600;
    color: var(--ys-ec-text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.25s ease;
    border-radius: 0;
}

.ys-ec-auth-tab:hover {
    color: var(--ys-ec-primary-dark);
    background: var(--ys-ec-primary-bg);
}

.ys-ec-auth-tab.active {
    color: var(--ys-ec-primary-dark);
    background: transparent;
    border-bottom-color: var(--ys-ec-primary);
    font-weight: 700;
}

/* --- Tab 面板（淡入動畫） --- */
.ys-ec-tab-panel {
    display: none;
    animation: ysEcFadeIn 0.2s ease;
}

.ys-ec-tab-panel.active {
    display: block;
}

/* --- 表單欄位（加大圓角） --- */
.ys-ec-auth-field {
    margin-bottom: 18px;
}

.ys-ec-auth-field > label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--ys-ec-text);
    margin-bottom: 6px;
}

.ys-ec-auth-field input[type="text"],
.ys-ec-auth-field input[type="email"],
.ys-ec-auth-field input[type="password"],
.ys-ec-auth-field input[type="tel"],
.ys-ec-auth-field input[type="date"],
.ys-ec-auth-field select {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--ys-ec-border);
    border-radius: var(--ys-ec-radius);
    font-size: 15px;
    color: var(--ys-ec-text);
    transition: border-color var(--ys-ec-transition), box-shadow var(--ys-ec-transition);
    box-sizing: border-box;
    background: var(--ys-ec-card-bg);
}

.ys-ec-auth-field input:focus,
.ys-ec-auth-field select:focus {
    border-color: var(--ys-ec-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(143, 168, 184, 0.2);
}

.ys-ec-required {
    color: var(--ys-ec-danger);
}

/* --- 記住我 + 忘記密碼排列 --- */
.ys-ec-auth-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ys-ec-auth-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--ys-ec-text);
    cursor: pointer;
}

.ys-ec-auth-checkbox input {
    margin: 0;
    accent-color: var(--ys-ec-primary);
}

.ys-ec-auth-forgot {
    font-size: 13px;
    color: var(--ys-ec-primary-dark);
    text-decoration: none;
}

.ys-ec-auth-forgot:hover {
    text-decoration: underline;
    color: var(--ys-ec-primary);
}

/* --- 兩欄排列（手機 + 國家） --- */
.ys-ec-auth-row-2col {
    display: flex;
    gap: 12px;
}

.ys-ec-auth-half {
    flex: 1;
    min-width: 0;
}

/* --- 按鈕 --- */
.ys-ec-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--ys-ec-radius);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    vertical-align: middle;
    box-sizing: border-box;
    cursor: pointer;
    transition: all var(--ys-ec-transition);
    text-decoration: none;
    font-family: var(--ys-ec-font);
}

.ys-ec-btn-primary,
a.ys-ec-btn-primary,
button.ys-ec-btn-primary {
    background: var(--ys-ec-primary-dark) !important;
    color: #fff !important;
    text-decoration: none;
}

.ys-ec-btn-primary:hover,
a.ys-ec-btn-primary:hover {
    background: #5a7a8a !important;
    color: #fff !important;
    box-shadow: 0 2px 8px rgba(143, 168, 184, 0.35);
    text-decoration: none;
}

.ys-ec-btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ys-ec-btn-block {
    display: flex;
    width: 100%;
    padding: 14px;
    font-size: 16px;
    justify-content: center;
}

/* --- 訊息區（Morandi 色系） --- */
.ys-ec-auth-message {
    padding: 12px 16px;
    border-radius: var(--ys-ec-radius);
    font-size: 14px;
    margin-top: 16px;
}

.ys-ec-msg-error {
    background: var(--ys-ec-danger-light);
    color: var(--ys-ec-danger-text, #8b4c4c);
    border: 1px solid rgba(192, 128, 128, 0.3);
}

.ys-ec-msg-success {
    background: var(--ys-ec-success-light);
    color: var(--ys-ec-success-text, #3d6b4a);
    border: 1px solid rgba(125, 171, 142, 0.3);
}

/* ======================================================
 * 用戶圖示與下拉選單（[ys_ec_user_icon]）
 * ====================================================== */

.ys-ec-user-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.ys-ec-user-icon-svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    transition: color var(--ys-ec-transition);
}

.ys-ec-user-icon:hover .ys-ec-user-icon-svg {
    color: var(--ys-ec-primary);
}

/* --- 觸發按鈕 --- */
.ys-ec-user-icon-trigger {
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 50%;
    transition: background var(--ys-ec-transition);
}

.ys-ec-user-icon-trigger:hover {
    background: var(--ys-ec-primary-bg);
}

/* --- 下拉選單 --- */
.ys-ec-user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    background: var(--ys-ec-card-bg);
    border-radius: var(--ys-ec-radius);
    box-shadow: var(--ys-ec-shadow-lg);
    border: 1px solid var(--ys-ec-border);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--ys-ec-transition);
    z-index: 9999;
}

.ys-ec-user-dropdown.ys-ec-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* --- 下拉選單 Header --- */
.ys-ec-user-dropdown-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--ys-ec-border-light);
}

.ys-ec-user-dropdown-header strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--ys-ec-text);
}

.ys-ec-user-dropdown-header small {
    display: block;
    font-size: 12px;
    color: var(--ys-ec-text-muted);
    margin-top: 2px;
    word-break: break-all;
}

/* --- 下拉選單項目 --- */
.ys-ec-user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    font-size: 14px;
    color: var(--ys-ec-text);
    text-decoration: none;
    transition: background var(--ys-ec-transition);
}

.ys-ec-user-dropdown-item:hover {
    background: var(--ys-ec-primary-bg);
}

.ys-ec-user-dropdown-item svg {
    flex-shrink: 0;
    color: var(--ys-ec-text-muted);
}

.ys-ec-user-logout {
    border-top: 1px solid var(--ys-ec-border-light);
    color: var(--ys-ec-danger);
}

.ys-ec-user-logout svg {
    color: var(--ys-ec-danger);
}

/* ======================================================
 * Toast 通知（Morandi 風格）
 * ====================================================== */

.ys-ec-toast {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background: var(--ys-ec-text);
    color: #fff;
    padding: 12px 20px;
    border-radius: var(--ys-ec-radius);
    font-size: 14px;
    z-index: 10000;
    animation: ys-ec-slide-up 0.3s ease;
    box-shadow: var(--ys-ec-shadow-hover);
    font-family: var(--ys-ec-font);
}

@keyframes ys-ec-slide-up {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ======================================================
 * 浮動購物車按鈕
 * ====================================================== */

.ys-ec-floating-cart {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ys-ec-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(143, 168, 184, 0.4);
    cursor: pointer;
    z-index: 999;
    transition: transform var(--ys-ec-transition), box-shadow var(--ys-ec-transition), background var(--ys-ec-transition);
    border: none;
}

.ys-ec-floating-cart:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(143, 168, 184, 0.5);
}

.ys-ec-floating-cart .cart-count {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--ys-ec-danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ======================================================
 * 響應式調整
 * ====================================================== */

@media (max-width: 576px) {
    .ys-ec-auth-overlay {
        align-items: stretch;
        padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }

    .ys-ec-auth-modal {
        height: calc(100dvh - 16px);
        max-height: calc(100dvh - 16px);
        padding: 12px 16px 24px;
        border-radius: var(--ys-ec-radius);
        max-width: 100%;
    }

    .ys-ec-auth-row-2col {
        flex-direction: column;
        gap: 0;
    }

    .ys-ec-auth-close {
        position: sticky;
        top: 0;
        right: auto;
        margin-left: auto;
        margin-bottom: 8px;
        box-shadow: var(--ys-ec-shadow);
        z-index: 3;
    }
}
