/**
 * カスタムデータベースツール - JSON出力のためのテーブルスタイル
 */

/* コンテナスタイル */
.cdt-json-container,
.cdt-hybrid-container {
    margin-bottom: 30px;
    position: relative;
}

/* テーブル基本スタイル */
.cdt-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    border: 1px solid #ddd;
}

.cdt-table th,
.cdt-table td {
    padding: 8px;
    border: 1px solid #ddd;
    text-align: left;
}

.cdt-table th {
    background-color: #f5f5f5;
    font-weight: bold;
}

.cdt-table tr:nth-child(even) {
    background-color: #f9f9f9;
}

.cdt-table tr:hover {
    background-color: #f0f0f0;
}

/* テーブルのレスポンシブ対応（横スクロール） */
.cdt-table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* iOSのスムーススクロール */
    position: relative;
}

/* スティッキーヘッダー */
.cdt-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #f5f5f5;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}

/* 固定列 */
.cdt-fixed-columns .cdt-fixed-col {
    position: sticky;
    left: 0;
    z-index: 5;
    background-color: inherit; /* 行の背景色を継承 */
    background-clip: padding-box;
    border-right: 2px solid #ddd; /* 固定列の右側に境界線 */
}

/* 固定列のヘッダー（スティッキーヘッダーと固定列の交差部分） */
.cdt-fixed-columns th.cdt-fixed-col {
    z-index: 15; /* 通常のヘッダーより上に表示 */
    background-color: #f5f5f5; /* ヘッダーの背景色 */
}

/* 奇数行の固定列背景色 */
.cdt-table tr:nth-child(odd) td.cdt-fixed-col {
    background-color: #ffffff;
}

/* 偶数行の固定列背景色 */
.cdt-table tr:nth-child(even) td.cdt-fixed-col {
    background-color: #f9f9f9;
}

/* ホバー時の固定列背景色 */
.cdt-table tr:hover td.cdt-fixed-col {
    background-color: #f0f0f0;
}

/* チェックボックス列 */
.cdt-checkbox-col {
    width: 30px;
    text-align: center;
    padding: 4px;
}

/* チェックボックス選択された行 */
.cdt-row-selected {
    background-color: rgba(66, 139, 202, 0.15) !important;
}

/* 検索フィールド */
.cdt-search-container {
    margin-bottom: 15px;
}

.cdt-search-input {
    padding: 8px;
    width: 100%;
    max-width: 300px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* チェックボックス操作ボタン */
.cdt-checkbox-controls {
    margin-bottom: 15px;
}

.cdt-checkbox-controls button {
    margin-right: 10px;
    padding: 6px 12px;
    background-color: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.cdt-checkbox-controls button:hover {
    background-color: #e9e9e9;
}

/* ソート機能 */
.cdt-sortable {
    cursor: pointer;
    position: relative;
    padding-right: 20px; /* ソートアイコン用のスペース */
}

.cdt-sort-icon {
    display: inline-block;
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    opacity: 0.3;
}

/* 昇順ソート */
th.sorted-asc .cdt-sort-icon:after {
    content: "";
    display: block;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #333;
    opacity: 1;
}

/* 降順ソート */
th.sorted-desc .cdt-sort-icon:after {
    content: "";
    display: block;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid #333;
    opacity: 1;
}

/* ソートされていない状態のアイコン */
.cdt-sortable:not(.sorted-asc):not(.sorted-desc) .cdt-sort-icon:after {
    content: "";
    display: block;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 3px solid #999;
    margin-bottom: 3px;
}

.cdt-sortable:not(.sorted-asc):not(.sorted-desc) .cdt-sort-icon:before {
    content: "";
    display: block;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 3px solid #999;
}

/* サムネイル画像 */
.cdt-thumbnail {
    max-width: 50px;
    max-height: 50px;
    object-fit: contain;
}

/* データロード状況 */
.cdt-json-status {
    margin-top: 15px;
    padding: 10px;
    background-color: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* さらに表示ボタン */
.cdt-load-more {
    padding: 6px 12px;
    background-color: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.cdt-load-more:hover {
    background-color: #e9e9e9;
}

/* ローディング表示 */
.cdt-loading {
    padding: 20px;
    text-align: center;
    background-color: rgba(255, 255, 255, 0.8);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.cdt-loading:after {
    content: "";
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    display: inline-block;
    animation: cdt-spin 1s linear infinite;
    margin-left: 10px;
}

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

/* エラー表示 */
.cdt-error {
    padding: 15px;
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    margin-bottom: 15px;
}

/* モバイル向けの調整 */
@media (max-width: 767px) {
    .cdt-checkbox-controls {
        display: flex;
        flex-direction: column;
    }
    
    .cdt-checkbox-controls button {
        margin-bottom: 5px;
    }
    
    .cdt-json-status {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .cdt-load-more {
        margin-top: 10px;
    }
}
