/**
 * 統合アバターアップロード CSS - 修正版
 * 統一されたクラス名を使用（競合回避）
 */

/* =================================================================
   統合アバター表示の改善
   ================================================================= */

/* プロフィールアバター */
.profile-avatar {
    position: relative;
    display: inline-block;
    margin-bottom: 20px;
}

/* アバターラッパー */
.avatar-wrapper {
    width: 120px;
    height: 120px;
    position: relative;
    margin: 0 auto;
    transition: transform 0.3s ease;
}

.avatar-wrapper.editable {
    cursor: pointer;
}

.avatar-wrapper.editable:hover {
    transform: scale(1.05);
}

.avatar-ring {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
}

/* アバター画像のスタイル統一 */

/* 認証バッジ */
.verified-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    background: #6c7ce7;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
    z-index: 2;
}

.verified-badge::after {
    content: '✓';
    color: #ffffff;
    font-size: 12px;
    font-weight: bold;
}

/* アバター編集オーバーレイ */
.avatar-edit-overlay {
    position: absolute;
    top: 6px;
    left: 6px;
    right: 6px;
    bottom: 6px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
    z-index: 3;
    pointer-events: none;
}

.avatar-wrapper.editable:hover .avatar-edit-overlay {
    opacity: 1;
}

/* =================================================================
   統合アバターアップロードモーダル
   ================================================================= */

/* モーダル基本スタイル */
.unified-avatar-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.unified-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.unified-modal-container {
    position: relative;
    background: #ffffff;
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    z-index: 1;
}

/* モーダルヘッダー */
.unified-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}

.unified-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
}

.unified-avatar-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6b7280;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.unified-avatar-modal-close:hover {
    background: #e5e7eb;
}

/* モーダルボディ */
.unified-modal-body {
    padding: 20px;
    max-height: 65vh;
    overflow-y: auto;
}

/* アップロードステップ */
.unified-upload-step {
    display: none;
}

.unified-upload-step.active {
    display: block;
}

/* アップロードエリア */
.unified-avatar-upload-area {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    margin-bottom: 30px;
}

.unified-avatar-upload-area:hover,
.unified-avatar-upload-area.dragover {
    border-color: #6c7ce7;
    background: #f0f4ff;
}

.unified-upload-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.unified-upload-text p {
    margin: 8px 0;
    color: #6b7280;
}

.unified-upload-note {
    font-size: 12px !important;
    color: #9ca3af !important;
}

/* 現在のアバターセクション */
.unified-current-avatar-section {
    text-align: center;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}

.unified-current-avatar-section h4 {
    margin: 0 0 15px;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}

.unified-current-avatar-preview {
    display: inline-block;
    margin-bottom: 15px;
}

.unified-current-avatar-preview img {
    width: 80px !important;
    height: 80px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
}

.no-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    font-size: 12px;
    margin: 0 auto;
}

/* クロップエリア */
.unified-crop-container {
    margin-bottom: 20px;
    max-height: 300px;
    overflow: hidden;
    border-radius: 8px;
}

.unified-crop-controls p {
    color: #6b7280;
    font-size: 14px;
    margin-bottom: 20px;
    text-align: center;
}

/* プレビューエリア */
.unified-crop-preview {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f9fafb;
    border-radius: 8px;
}

.unified-preview-item {
    text-align: center;
}

.unified-preview-label {
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 8px;
}

.unified-preview-full,
.unified-preview-thumb {
    border: 2px solid #e5e7eb;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
}

.unified-preview-full {
    width: 79px;
    height: 79px;
}

.unified-preview-thumb {
    width: 29px;
    height: 29px;
}

/* アクションボタン */
.unified-crop-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* ローディング */
.unified-modal-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

.unified-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-left: 4px solid #6c7ce7;
    border-radius: 50%;
    animation: unified-spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes unified-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.unified-loading-text {
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
    margin: 0;
}

/* =================================================================
   ボタンスタイル
   ================================================================= */

.btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
}

.btn-primary {
    background: #6c7ce7;
    color: #ffffff;
}

.btn-primary:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.btn-secondary:hover {
    background: #e5e7eb;
}

.btn-outline {
    background: transparent;
    color: #6b7280;
    border: 1px solid #d1d5db;
}

.btn-outline:hover {
    background: #f3f4f6;
    color: #374151;
    border-color: #9ca3af;
}

/* =================================================================
   通知（トースト）
   ================================================================= */

.unified-avatar-toast {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* =================================================================
   レスポンシブデザイン
   ================================================================= */

@media (max-width: 768px) {
    .avatar-wrapper {
        width: 100px;
        height: 100px;
    }
    
    .avatar-ring {
        width: 100px;
        height: 100px;
        padding: 5px;
    }
    
    .avatar-wrapper img,
    .avatar-ring img,
    .profile-avatar img,
    .avatar,
    img.avatar {
        width: 90px !important;
        height: 90px !important;
    }
    
    .avatar-edit-overlay {
        top: 5px;
        left: 5px;
        right: 5px;
        bottom: 5px;
        font-size: 11px;
    }
    
    .unified-modal-container {
        width: 95%;
        max-height: 90vh;
    }

    .unified-modal-body {
        padding: 15px;
        max-height: 75vh;
    }

    .unified-avatar-upload-area {
        padding: 30px 15px;
    }

    .unified-crop-actions {
        flex-direction: column;
    }

    .unified-crop-preview {
        flex-direction: column;
        gap: 15px;
    }
}

@media (max-width: 480px) {
    .avatar-wrapper {
        width: 90px;
        height: 90px;
    }
    
    .avatar-ring {
        width: 90px;
        height: 90px;
        padding: 4px;
    }
    
    .avatar-wrapper img,
    .avatar-ring img,
    .profile-avatar img,
    .avatar,
    img.avatar {
        width: 82px !important;
        height: 82px !important;
    }
    
    .unified-modal-container {
        width: 98%;
        margin: 10px;
    }
    
    .unified-modal-header {
        padding: 15px;
    }
    
    .unified-modal-header h3 {
        font-size: 16px;
    }
    
    .unified-upload-icon {
        font-size: 36px;
    }
    
    .unified-crop-preview {
        padding: 10px;
    }
}

/* =================================================================
   既存のBuddyPressアバタースタイルとの競合回避
   ================================================================= */

#buddypress .avatar-wrapper img {
    width: 108px !important;
    height: 108px !important;
    border-radius: 50% !important;
}

#buddypress .profile-avatar img {
    border-radius: 50% !important;
}

/* BuddyPressのデフォルトアバタースタイルをオーバーライド */
#buddypress #item-header-avatar img.avatar,
#buddypress .item-avatar img.avatar {
    border-radius: 50% !important;
}

/* =================================================================
   アニメーション効果
   ================================================================= */

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.unified-avatar-modal {
    animation: fadeInScale 0.3s ease-out;
}

/* フォーカス管理 */
.unified-avatar-modal:focus-within {
    outline: none;
}

.btn:focus,
.unified-avatar-modal-close:focus {
    outline: 2px solid #6c7ce7;
    outline-offset: 2px;
}

/* アクセシビリティ */
@media (prefers-reduced-motion: reduce) {
    .avatar-wrapper,
    .avatar-edit-overlay,
    .btn,
    .unified-avatar-modal {
        transition: none;
        animation: none;
    }
}

/* ハイコントラストモード対応 */
@media (prefers-contrast: high) {
    .unified-modal-container {
        border: 2px solid #000;
    }
    
    .btn-primary {
        background: #000;
        color: #fff;
        border: 2px solid #000;
    }
    
    .btn-outline {
        border: 2px solid #000;
        color: #000;
    }
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
    .unified-modal-container {
        background: #1f2937;
        color: #f9fafb;
    }
    
    .unified-modal-header {
        background: #374151;
        border-bottom-color: #4b5563;
    }
    
    .unified-modal-header h3 {
        color: #f9fafb;
    }
    
    .unified-avatar-upload-area {
        background: #374151;
        border-color: #6b7280;
    }
    
    .unified-upload-text p,
    .unified-crop-controls p {
        color: #d1d5db;
    }
    
    .unified-upload-note {
        color: #9ca3af !important;
    }
    
    .unified-crop-preview {
        background: #374151;
    }
    
    .unified-preview-label {
        color: #9ca3af;
    }
    
    .unified-loading-text {
        color: #d1d5db;
    }
}

/* =================================================================
   旧クラス名との互換性維持（段階的移行用）
   ================================================================= */

/* 旧oceanwp-child-*クラス名を統一クラス名にマッピング */
.oceanwp-child-avatar-modal {
    @extend .unified-avatar-modal;
}

.oceanwp-child-modal-backdrop {
    @extend .unified-modal-backdrop;
}

.oceanwp-child-modal-container {
    @extend .unified-modal-container;
}

/* 注意: @extendが使えない環境の場合は以下のような形で記述 */
.oceanwp-child-avatar-modal,
.unified-avatar-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.oceanwp-child-modal-backdrop,
.unified-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

/* スマホ時はボタン上下を逆にする */
@media (max-width: 768px) {
  .unified-crop-actions {
    display: flex;               /* 念のため */
    flex-direction: column-reverse !important; /* 反転のキモ */
    gap: 10px;                   /* 任意：間隔 */
  }
  .unified-crop-actions .btn {
    width: 100%;                 /* 任意：横幅そろえ */
  }
}


/* 既存のコードとの互換性のため、一部の重複スタイルを維持 */