/**
 * Product Comparison Frontend Styles
 * AFFINGER6EX最適化版
 */

/* 基本設定 */
.product-comparison-wrapper,
.product-spec-wrapper,
.product-list-wrapper {
    max-width: 100%;
    margin: 20px 0;
    font-family: inherit;
}

.affinger-optimized {
    --primary-color: #007cba;
    --secondary-color: #666;
    --border-color: #ddd;
    --background-color: #f9f9f9;
    --text-color: #333;
    --highlight-color: #ff4500;
}

/* 商品比較テーブル */
.comparison-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px;
    background: var(--background-color);
    border-radius: 8px;
}

.comparison-title {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.5em;
}

.comparison-count {
    background: var(--primary-color);
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.9em;
}

.comparison-table-container {
    overflow-x: auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    border: 1px solid var(--border-color);
}

.product-comparison-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 700px;
    table-layout: fixed;
}

.product-comparison-table thead {
    display: table-header-group;
}

.product-comparison-table tbody {
    display: table-row-group;
}

.product-comparison-table tr {
    display: table-row;
}

.product-comparison-table th,
.product-comparison-table td {
    display: table-cell;
}

.product-comparison-table th,
.product-comparison-table td {
    padding: 12px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    vertical-align: top;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.product-comparison-table th {
    text-align: center;
}

.product-comparison-table th {
    font-weight: bold;
    position: sticky;
    top: 0;
    z-index: 10;
    text-align: center;
    border-right: 1px solid var(--border-color);
}

/* 商品名ヘッダーを白背景・黒文字に */
.product-comparison-table thead tr th.product-header {
    background: white !important;
    background-color: white !important;
    color: var(--text-color) !important;
}

.first-column-header {
    background: var(--primary-color);
    color: white;
    font-weight: bold;
    font-size: 15px;
    width: 150px;
    min-width: 150px;
    text-align: left !important;
}

.spec-label {
    background: var(--primary-color);
    color: white;
    font-weight: bold;
    width: 150px;
    min-width: 150px;
}

.product-header {
    text-align: center;
    min-width: 180px;
    max-width: 220px;
    padding: 12px 8px;
    font-weight: bold;
    font-size: 1.0em;
    color: var(--text-color) !important;
    background: white !important;
    white-space: normal;
    word-wrap: break-word;
    line-height: 1.2;
    overflow-wrap: break-word;
    vertical-align: top;
}

/* 商品ヘッダー内の画像 */
.product-header .product-image {
    margin-bottom: 10px;
    text-align: center;
}

.product-header .product-image img {
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    transition: transform 0.3s ease;
}

.product-header .product-image img:hover {
    transform: scale(1.05);
}

.product-header .product-name {
    font-size: 14px;
    line-height: 1.2;
    margin-top: 8px;
    color: var(--primary-color) !important;
    font-weight: bold;
    text-align: center;
}

/* 商品名ヘッダーのスタイル統一 */
.product-comparison-table .product-header .product-name {
    color: var(--primary-color) !important;
}

.brand-row {
    background: #f8f9fa;
}

.brand-value {
    color: var(--secondary-color);
    font-weight: 500;
    text-align: center;
}

.price-row {
    background: #f0f8ff;
    font-weight: bold;
}

.price-value {
    color: var(--highlight-color);
    font-weight: bold;
    font-size: 1.1em;
    text-align: center;
    line-height: 1.4;
    white-space: pre-line;
}

.spec-row:nth-child(even) {
    background: #f8f9fa;
}

.spec-value {
    text-align: center;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.3;
    min-width: 120px;
}

/* アフィリエイトリンク行 */
.affiliate-row {
    background: #f0f8ff;
    border-top: 2px solid var(--border-color);
}

.affiliate-row .spec-label {
    background: var(--primary-color) !important;
    color: white !important;
    border-top: 2px solid var(--border-color) !important;
    border-right: 1px solid var(--border-color) !important;
    position: relative;
}

/* 購入リンク行のセル境界を強調 */
.affiliate-row td:not(.spec-label) {
    border-left: 1px solid var(--border-color) !important;
}

.affiliate-links-cell {
    text-align: center;
    padding: 15px 8px;
    vertical-align: middle;
}

.affiliate-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
}

.affiliate-btn {
    display: inline-block;
    padding: 8px 12px;
    margin: 2px;
    border-radius: 6px;
    text-decoration: none;
    font-weight: bold;
    font-size: 12px;
    color: white;
    min-width: 70px;
    text-align: center;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
}

.affiliate-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    text-decoration: none;
    color: white;
}

/* プラットフォーム別カラー */
.affiliate-btn.amazon {
    background: #ff9900;
}

.affiliate-btn.amazon:hover {
    background: #e68900;
}

.affiliate-btn.rakuten {
    background: #bf0000;
}

.affiliate-btn.rakuten:hover {
    background: #a00000;
}

.affiliate-btn.yahoo {
    background: #ff0033;
}

.affiliate-btn.yahoo:hover {
    background: #cc0029;
}

.affiliate-btn.mercari {
    background: #ff4757;
}

.affiliate-btn.mercari:hover {
    background: #ff3742;
}

.affiliate-btn.official {
    background: #27ae60;
}

.affiliate-btn.official:hover {
    background: #229954;
}

.affiliate-btn.other {
    background: #6c757d;
}

.affiliate-btn.other:hover {
    background: #5a6268;
}

.no-links {
    color: var(--secondary-color);
    font-style: italic;
}

/* 比較カード */
.comparison-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.product-comparison-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.product-comparison-card:hover {
    transform: translateY(-5px);
}

.card-header {
    text-align: center;
    margin-bottom: 15px;
}

.card-header img {
    width: 150px;
    height: 150px;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 10px;
}

.card-specs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.spec-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.spec-key {
    font-weight: bold;
    color: var(--secondary-color);
}

.spec-value {
    color: var(--text-color);
}

/* 単一商品スペック */
.product-spec-card {
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin: 20px 0;
}

.product-header {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.product-image {
    flex-shrink: 0;
}

.product-image img {
    width: 150px;
    height: 150px;
    object-fit: cover;
    border-radius: 12px;
}

.product-info {
    flex: 1;
}

.product-info h3 {
    margin: 0 0 10px 0;
    color: var(--primary-color);
}

.product-specifications h4 {
    color: var(--primary-color);
    margin-bottom: 15px;
}

.specs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
}

.product-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.btn-add-comparison,
.btn-view-spec,
.btn-view-similar {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

.btn-add-comparison {
    background: var(--primary-color);
    color: white;
}

.btn-add-comparison:hover {
    background: #005a87;
}

.btn-view-spec,
.btn-view-similar {
    background: var(--background-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-view-spec:hover,
.btn-view-similar:hover {
    background: var(--border-color);
}

/* 商品一覧 */
.product-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px;
    background: var(--background-color);
    border-radius: 8px;
}

.list-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.sort-select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: white;
}

.layout-toggle {
    display: flex;
    gap: 5px;
}

.layout-btn {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 6px;
    cursor: pointer;
}

.layout-btn.active {
    background: var(--primary-color);
    color: white;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.product-item {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.product-item:hover {
    transform: translateY(-3px);
}

.product-item img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 15px;
}

.products-list .product-item-list {
    display: flex;
    align-items: center;
    gap: 20px;
    background: white;
    padding: 20px;
    margin-bottom: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.products-list .product-image {
    flex-shrink: 0;
}

.products-list .product-image img {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 8px;
}

.products-list .product-info {
    flex: 1;
}

.product-specs {
    display: flex;
    gap: 15px;
    margin-top: 10px;
}

.spec-item {
    background: var(--background-color);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* 比較パネル */
.comparison-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 300px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.comparison-panel .comparison-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--primary-color);
    color: white;
    border-radius: 12px 12px 0 0;
}

.close-panel {
    background: none;
    border: none;
    color: white;
    font-size: 1.5em;
    cursor: pointer;
}

.comparison-items {
    padding: 15px;
    max-height: 200px;
    overflow-y: auto;
}

.comparison-actions {
    padding: 15px;
    display: flex;
    gap: 10px;
}

.btn-compare,
.btn-clear {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

.btn-compare {
    background: var(--primary-color);
    color: white;
}

.btn-clear {
    background: var(--secondary-color);
    color: white;
}

/* フッター */
.comparison-footer {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
    padding: 20px;
    background: var(--background-color);
    border-radius: 8px;
}

.comparison-reset,
.comparison-share {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

.comparison-reset {
    background: var(--secondary-color);
    color: white;
}

.comparison-share {
    background: var(--highlight-color);
    color: white;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .comparison-header,
    .product-list-header {
        flex-direction: column;
        gap: 15px;
    }
    
    .product-header {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .comparison-table-container {
        font-size: 0.9em;
    }
    
    .products-grid {
        grid-template-columns: 1fr;
    }
    
    .products-list .product-item-list {
        flex-direction: column;
        text-align: center;
    }
    
    .comparison-panel {
        width: 90%;
        right: 5%;
    }
    
    /* モバイルでのアフィリエイトボタン調整 */
    .affiliate-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
    }
    
    .affiliate-btn {
        font-size: 11px;
        padding: 6px 8px;
        min-width: 60px;
    }
    
    /* モバイルでの商品画像調整 */
    .product-header .product-image img {
        width: 90px;
        height: 90px;
    }
    
    .product-header {
        min-width: 150px;
        max-width: 180px;
        padding: 10px 6px;
    }
}

/* エラーメッセージ */
.product-comparison-error,
.product-spec-error,
.product-list-error {
    background: #ffebee;
    color: #c62828;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    margin: 20px 0;
}