/* ============================================================
   全站註冊 Modal 樣式
   ============================================================ */

.modal-overlay,
.modal-container,
.modal-form,
.form-group,
.email-otp-row {
    box-sizing: border-box;
}

.modal-overlay *,
.modal-overlay *::before,
.modal-overlay *::after {
    box-sizing: border-box;
}

/* Modal 覆蓋層 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(20, 13, 9, 0.85);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-x: hidden;
    overflow-y: auto;
    animation: modalFadeIn 0.3s ease;
    --ms-gold: #E5B842;
    --ms-gold-light: #F3D978;
    --ms-gold-deep: #C4922A;
    --ms-gold-bronze: #A9761F;
    --ms-oak-light: #6B4A2F;
    --ms-text: #2A1C14;
    --ms-text-muted: #6B5748;
    --ms-danger: #B3452F;
    --ms-success: #3F7D4A;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Modal 容器 */
.modal-container {
    position: relative;
    width: 100%;
    max-width: 500px;
    min-width: 0;
    background: linear-gradient(135deg, #F4E8C1 0%, #E8D9A8 100%);
    border-radius: 16px;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.5),
        inset 0 2px 0 rgba(255, 255, 255, 0.3),
        0 0 0 3px var(--ms-gold-bronze, #A9761F);
    max-height: 90vh;
    max-height: calc(100dvh - 40px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    animation: modalSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 關閉按鈕 */
.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(45, 31, 23, 0.1);
    color: var(--ms-text);
    font-size: 28px;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
}

.modal-close:hover {
    background: var(--ms-danger);
    color: white;
    transform: rotate(90deg);
}

/* 進度指示器 */
.modal-progress {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 20px 16px;
    border-bottom: 2px solid var(--ms-gold-bronze);
}

.modal-progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: white;
    border: 3px solid #D4C5A9;
    color: var(--ms-text-muted);
    font-weight: 700;
    font-size: 16px;
    transition: all 0.3s ease;
}

.modal-progress-step.active .step-number {
    background: var(--ms-gold);
    border-color: var(--ms-gold-deep);
    color: white;
    box-shadow: 0 4px 12px rgba(229, 184, 66, 0.5);
}

.modal-progress-step.completed .step-number {
    background: var(--ms-success);
    border-color: var(--ms-success);
    color: white;
}

.step-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--ms-text-muted);
    transition: color 0.3s ease;
}

.modal-progress-step.active .step-label {
    color: var(--ms-text);
}

.modal-progress-line {
    width: 60px;
    height: 3px;
    background: #D4C5A9;
    margin: 0 8px;
    position: relative;
    top: -18px;
}

/* Modal 內容 */
.modal-step {
    padding: 32px 28px;
}

.modal-header {
    text-align: center;
    margin-bottom: 28px;
}

.modal-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--ms-text);
    margin-bottom: 8px;
    letter-spacing: 0.05em;
}

.modal-subtitle {
    font-size: 14px;
    color: var(--ms-text-muted);
    line-height: 1.6;
}

.modal-subtitle strong {
    color: var(--ms-gold-deep);
    font-weight: 700;
}

.modal-pc-notice {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 12px 0 0;
    padding: 10px 12px;
    background: rgba(179, 69, 47, 0.08);
    border: 1px solid rgba(179, 69, 47, 0.28);
    border-radius: 8px;
    color: var(--ms-text, #2A1C14);
    font-size: 13px;
    line-height: 1.5;
    text-align: left;
}

.modal-pc-notice i {
    color: var(--ms-danger, #B3452F);
    margin-top: 2px;
    flex-shrink: 0;
}

.modal-pc-notice strong {
    color: var(--ms-danger, #B3452F);
    font-weight: 700;
}

/* 成功圖示 */
.modal-success-icon {
    width: 64px;
    height: 64px;
    background: var(--ms-success);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    margin: 0 auto 20px;
    box-shadow: 0 6px 20px rgba(63, 125, 74, 0.4);
}

/* 表單 */
.modal-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
}

.email-otp-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

.email-otp-row input {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
}

.email-otp-row .modal-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 12px 14px;
    margin: 0;
}

.form-group label {
    font-size: 14px;
    font-weight: 700;
    color: var(--ms-text);
    letter-spacing: 0.03em;
}

.form-group input {
    padding: 12px 16px;
    font-size: 16px;
    min-height: 44px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border: 2px solid var(--ms-oak-light);
    border-radius: 8px;
    background: white;
    color: var(--ms-text);
    font-family: inherit;
    transition: all 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--ms-gold);
    box-shadow: 0 0 0 4px rgba(229, 184, 66, 0.15);
}

.form-group input.code-input {
    font-size: 24px;
    letter-spacing: 8px;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-weight: 700;
}

.form-hint {
    font-size: 12px;
    color: var(--ms-text-muted);
    font-style: italic;
}

/* 錯誤提示 */
.modal-error {
    padding: 12px 16px;
    background: rgba(179, 69, 47, 0.1);
    border-left: 4px solid var(--ms-danger);
    border-radius: 6px;
    color: var(--ms-danger);
    font-size: 14px;
    font-weight: 600;
    transition: opacity 0.3s ease;
}

/* 按鈕 */
.modal-btn {
    min-height: 44px;
    min-width: 0;
    max-width: 100%;
    padding: 14px 24px;
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    letter-spacing: 0.04em;
}

.modal-btn-primary {
    background: linear-gradient(135deg, var(--ms-gold), var(--ms-gold-deep));
    color: white;
    box-shadow: 0 4px 12px rgba(229, 184, 66, 0.4);
}

.modal-btn-primary:hover {
    background: linear-gradient(135deg, var(--ms-gold-light), var(--ms-gold));
    box-shadow: 0 6px 16px rgba(229, 184, 66, 0.6);
    transform: translateY(-2px);
}

.modal-btn-primary:active {
    transform: translateY(0);
}

.modal-btn-primary:disabled {
    background: #D4C5A9;
    cursor: not-allowed;
    box-shadow: none;
}

.modal-btn-secondary {
    background: white;
    color: var(--ms-text);
    border: 2px solid var(--ms-oak-light);
}

.modal-btn-secondary:hover {
    background: #F4E8C1;
    border-color: var(--ms-gold-bronze);
}

.modal-btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loading Spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Footer */
.modal-footer {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(45, 31, 23, 0.1);
    text-align: center;
}

.modal-footer-text {
    font-size: 14px;
    color: var(--ms-text-muted);
}

.modal-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--ms-gold-deep);
    font-weight: 700;
    text-decoration: none;
    transition: color 0.2s ease;
}

.modal-link:hover {
    color: var(--ms-gold);
    text-decoration: underline;
}

/* 完成步驟動作卡片 */
.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.modal-action-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: white;
    border: 2px solid var(--ms-oak-light);
    border-radius: 10px;
    text-decoration: none;
    color: var(--ms-text);
    transition: all 0.3s ease;
}

.modal-action-card:hover {
    border-color: var(--ms-gold);
    box-shadow: 0 4px 12px rgba(229, 184, 66, 0.3);
    transform: translateY(-2px);
}

.action-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.action-content h3 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 4px;
}

.action-content {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* 註冊完成後的資料保存 */
.account-save-kit {
    margin-bottom: 24px;
    padding: 18px;
    border: 2px solid var(--ms-gold-bronze);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.6);
    color: var(--ms-text);
    overflow-wrap: anywhere;
}

.account-save-kit h3 {
    margin: 0 0 10px;
    font-size: 18px;
}

.account-save-intro,
.account-password-warning,
.account-save-location,
.account-save-status {
    margin: 10px 0;
    font-size: 13px;
    line-height: 1.7;
}

.account-save-details {
    margin: 16px 0;
}

.account-save-details > div {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    align-items: baseline;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid rgba(45, 31, 23, 0.12);
    font-size: 14px;
    line-height: 1.7;
}

.account-save-details dt {
    font-weight: 700;
}

.account-save-details dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}

.account-save-details a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    max-width: 100%;
    color: #70451A;
    text-decoration: underline;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.account-password-option {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

.account-password-option input {
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: #8C611A;
}

.account-password-warning {
    color: var(--ms-danger);
}

.account-save-buttons {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    margin: 16px 0;
}

.account-save-buttons .modal-btn {
    width: 100%;
    padding: 14px 10px;
    white-space: normal;
}

.account-save-buttons .modal-btn-primary {
    color: var(--ms-text);
}

.account-save-status {
    font-weight: 700;
}

.account-save-status:empty,
.modal-overlay [hidden] {
    display: none !important;
}

#account-copy-fallback label {
    display: block;
    margin: 12px 0 8px;
    font-size: 14px;
    line-height: 1.6;
}

#account-copy-text {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 160px;
    padding: 10px;
    border: 2px solid var(--ms-oak-light);
    border-radius: 8px;
    color: var(--ms-text);
    background: white;
    font-size: 16px;
    font-family: inherit;
    line-height: 1.6;
    resize: vertical;
    overflow-wrap: anywhere;
}

.modal-overlay :is(button, a, input, textarea):focus-visible {
    outline: 3px solid #70451A;
    outline-offset: 3px;
}

.action-content p {
    font-size: 13px;
    color: var(--ms-text-muted);
    margin: 0;
}

/* 響應式 */
@media (max-width: 576px) {
    .modal-overlay {
        padding: 0;
        align-items: stretch;
        justify-content: flex-start;
    }

    .modal-container {
        max-width: 100%;
        width: 100%;
        border-radius: 0;
        max-height: 100vh;
        height: 100vh;
        max-height: 100dvh;
        height: 100dvh;
        min-height: 0;
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        box-shadow: none;
    }

    .modal-progress {
        padding: 20px 16px 12px;
        overflow: hidden;
    }

    .modal-progress-line {
        width: 32px;
        margin: 0 4px;
    }
    
    .modal-step {
        padding: 20px 16px;
    }

    .account-save-kit {
        padding: 14px;
    }

    .account-save-details > div {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
    }
    
    .modal-title {
        font-size: 22px;
        word-break: break-word;
    }

    .modal-header {
        margin-bottom: 20px;
    }

    .modal-pc-notice {
        font-size: 12px;
        padding: 8px 10px;
    }

    .form-group input.code-input {
        font-size: 20px;
        letter-spacing: 4px;
    }

    .email-otp-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .email-otp-row .modal-btn {
        width: 100%;
        padding: 12px 16px;
    }
    
    .step-label {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .modal-overlay,
    .modal-container,
    .modal-overlay * {
        animation: none;
        transition: none;
    }
}
