/**
 * CDT Sort Styles
 * カスタムデータベースツール用のソート機能スタイルシート
 */

/* ===============================================
   ソート可能なヘッダーのスタイル
   =============================================== */

/* ソート可能なヘッダーセル */
.cdt-table thead th.cdt-sortable {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    position: relative;
    padding-right: 24px; /* ソートアイコン用のスペース */
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* ホバー時の背景色 */
.cdt-table thead th.cdt-sortable:hover {
    background-color: #f0f0f0;
    color: #0073aa;
}

/* アクティブ（ソート中）のヘッダー */
.cdt-table thead th.cdt-sortable.cdt-sort-active {
    background-color: #e8f4f8;
    color: #0073aa;
    font-weight: 600;
}

/* ===============================================
   ソートアイコンのスタイル
   =============================================== */

/* ソートアイコンのコンテナ */
.cdt-sort-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.3;
    transition: opacity 0.2s ease;
}

/* ホバー時にアイコンを表示 */
.cdt-sortable:hover .cdt-sort-icon {
    opacity: 0.6;
}

/* アクティブ時にアイコンを強調 */
.cdt-sortable.cdt-sort-active .cdt-sort-icon {
    opacity: 1;
}

/* デフォルトのソートアイコン（両矢印） */
.cdt-sort-icon::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

/* 上向き矢印（デフォルト状態） */
.cdt-sort-icon::before {
    top: 2px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 6px solid #999;
}

.cdt-sort-icon::after {
    content: '';
    display: block;
    width: 0;
    height: 0;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 2px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid #999;
}

/* 昇順ソート時のアイコン */
.cdt-sort-icon.asc::before {
    border-bottom-color: #0073aa;
}

.cdt-sort-icon.asc::after {
    opacity: 0.2;
}

/* 降順ソート時のアイコン */
.cdt-sort-icon.desc::before {
    opacity: 0.2;
}

.cdt-sort-icon.desc::after {
    border-top-color: #0073aa;
}

/* ===============================================
   代替スタイル: Unicode矢印を使用
   （上記のCSSが動作しない場合のフォールバック）
   =============================================== */

/* Unicode矢印を使用する場合のスタイル */
.cdt-sort-icon-unicode {
    font-family: monospace;
    font-size: 12px;
    line-height: 1;
    color: #999;
}

.cdt-sortable:hover .cdt-sort-icon-unicode {
    color: #0073aa;
}

.cdt-sortable.sorted-asc .cdt-sort-icon-unicode::after {
    content: ' ▲';
    color: #0073aa;
}

.cdt-sortable.sorted-desc .cdt-sort-icon-unicode::after {
    content: ' ▼';
    color: #0073aa;
}

/* ===============================================
   テーブル行のハイライト
   =============================================== */

/* ソート中の列をハイライト表示（オプション） */
.cdt-table.cdt-highlight-sorted-column tbody td[data-column] {
    transition: background-color 0.3s ease;
}

.cdt-table.cdt-highlight-sorted-column.sorted-asc tbody td[data-column],
.cdt-table.cdt-highlight-sorted-column.sorted-desc tbody td[data-column] {
    position: relative;
}

/* ソート中のカラムのセルにハイライトを適用 */
.cdt-table.cdt-highlight-sorted-column thead th.cdt-sort-active ~ tbody tr td:nth-child(n) {
    /* nth-childはJavaScriptで動的に設定する必要があるため、ここでは一般的なスタイルのみ */
}

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

/* ソート実行中のローディングアニメーション */
.cdt-table.cdt-sorting {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.cdt-table.cdt-sorting::after {
    content: '';
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin-left: -20px;
    margin-top: -20px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #0073aa;
    border-radius: 50%;
    animation: cdt-spin 1s linear infinite;
}

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

/* ===============================================
   レスポンシブ対応
   =============================================== */

@media screen and (max-width: 768px) {
    /* モバイルではソートアイコンを小さく */
    .cdt-sort-icon {
        width: 12px;
        height: 12px;
    }

    .cdt-sort-icon::before,
    .cdt-sort-icon::after {
        border-left-width: 4px;
        border-right-width: 4px;
    }

    .cdt-sort-icon::before {
        border-bottom-width: 5px;
    }

    .cdt-sort-icon::after {
        border-top-width: 5px;
    }

    /* ヘッダーのパディングを調整 */
    .cdt-table thead th.cdt-sortable {
        padding-right: 20px;
    }
}

/* ===============================================
   ダークモード対応（オプション）
   =============================================== */

@media (prefers-color-scheme: dark) {
    .cdt-table thead th.cdt-sortable:hover {
        background-color: #2c2c2c;
        color: #4a9eff;
    }

    .cdt-table thead th.cdt-sortable.cdt-sort-active {
        background-color: #1e3a5f;
        color: #4a9eff;
    }

    .cdt-sort-icon::before,
    .cdt-sort-icon::after {
        border-bottom-color: #666;
        border-top-color: #666;
    }

    .cdt-sort-icon.asc::before {
        border-bottom-color: #4a9eff;
    }

    .cdt-sort-icon.desc::after {
        border-top-color: #4a9eff;
    }

    .cdt-table.cdt-sorting::after {
        border-color: #444;
        border-top-color: #4a9eff;
    }
}

/* ===============================================
   アクセシビリティ対応
   =============================================== */

/* フォーカス時のアウトライン */
.cdt-table thead th.cdt-sortable:focus {
    outline: 2px solid #0073aa;
    outline-offset: -2px;
}

/* キーボードナビゲーション用 */
.cdt-table thead th.cdt-sortable:focus:not(:focus-visible) {
    outline: none;
}

.cdt-table thead th.cdt-sortable:focus-visible {
    outline: 2px solid #0073aa;
    outline-offset: -2px;
}

/* スクリーンリーダー用の説明テキスト */
.cdt-sort-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ===============================================
   印刷用スタイル
   =============================================== */

@media print {
    /* 印刷時はソートアイコンを非表示 */
    .cdt-sort-icon {
        display: none;
    }

    /* ハイライトを無効化 */
    .cdt-table thead th.cdt-sortable.cdt-sort-active {
        background-color: transparent;
        font-weight: normal;
    }
}
