/* =============================================
   GEAL Product Cards, Grids & Favorites
   ============================================= */

.dashboard-grid-section {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 6px 4px;
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    background-color: transparent;
    box-sizing: border-box;
}

.dashboard-grid-section > h3,
.dashboard-grid-section .dashboard-section > h3 {
    margin: 0 0 4px 0;
    padding: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--geal-text-primary);
    line-height: 1.3;
}

.dashboard-grid-section > .info-card,
.dashboard-grid-section .dashboard-section > .info-card {
    margin: 0 0 8px 0;
}

.info-card {
    background: var(--geal-bg-card);
    padding: 4px;
    border-radius: var(--geal-radius-md);
    box-shadow: var(--geal-shadow-sm-strong);
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: transform var(--geal-transition);
}

.info-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--geal-shadow-md);
}

.info-card h3 {
    font-size: 20px;
    font-family: var(--font-body);
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--geal-text-primary);
}

.grid-2x2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    flex-grow: 1;
}

@media (min-width: 768px) {
    .grid-2x2 { grid-template-columns: repeat(5, 1fr); gap: 8px; }
}

@media (min-width: 1024px) {
    .grid-2x2 { grid-template-columns: repeat(6, 1fr); gap: 8px; }
}

@media (min-width: 1440px) {
    .grid-2x2 { grid-template-columns: repeat(8, 1fr); gap: 8px; }
}

.grid-2x2 .product-item .minimal-overlay {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 60px;
}

/* --- Product Item --- */

.product-item {
    position: relative;
    background: var(--geal-bg-card);
    border-radius: var(--geal-radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--geal-border-lighter);
    box-shadow: var(--geal-shadow-xs);
    cursor: pointer;
    /* perf: 画面外カードのレンダリングを後回し → 初期描画/スクロールを軽く (体感速度)。
       contain-intrinsic-size の auto で実寸を記憶しスクロールバーのガタつきを防ぐ。 */
    content-visibility: auto;
    contain-intrinsic-size: auto 240px;
}

.product-item > img,
.product-item > img:first-child {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-bottom: 1px solid var(--geal-border-light);
    display: block;
}

.minimal-overlay {
    padding: 4px;
    background: var(--geal-bg-card);
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-grow: 1;
}

.badges-row {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 20px;
}

.cert-marks {
    display: flex;
    gap: 3px;
}

.cert-marks img {
    height: 16px;
    width: auto;
    object-fit: contain;
}

.product-title {
    font-size: 11px;
    font-family: var(--font-body);
    font-weight: 500;
    color: var(--geal-text-primary);
    margin: 0 0 2px 0;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
    box-orient: vertical;
    overflow: hidden;
}

.price-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 4px;
}

.main-price {
    font-size: 13px;
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--geal-text-primary);
}

/* --- Sale Price --- */

.geal-sale-badge {
    display: inline-block;
    background: var(--geal-danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: var(--geal-radius-sm);
    margin-right: 4px;
    vertical-align: middle;
    line-height: 1.5;
}

.geal-sale-price {
    color: var(--geal-text-primary);
}

.geal-original-price {
    font-size: 12px;
    color: var(--geal-text-faint);
    text-decoration: line-through;
    margin-left: 6px;
    vertical-align: middle;
}

.geal-sale-countdown {
    font-size: 11px;
    color: var(--geal-danger);
    font-weight: 600;
    margin-top: 2px;
}

/* --- Image Overlay Badges --- */

.geal-img-discount-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    background: var(--geal-danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: var(--geal-radius-sm);
    z-index: 2;
    pointer-events: none;
    line-height: 1.2;
}

.geal-rank-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    font-size: 18px;
    z-index: 2;
    pointer-events: none;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

/* --- Price + Cert Row --- */

.price-cert-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 2px;
}

.inline-cert-img {
    height: 14px;
    width: auto;
    vertical-align: middle;
    cursor: pointer;
    flex-shrink: 0;
}

.inline-status-badge {
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    padding: 1px 4px;
    border-radius: 3px;
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
}

/* --- Card Actions --- */

.card-actions {
    margin-top: 4px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.mini-cart-btn {
    padding: 5px 12px;
    background: #ffd814;
    color: #111;
    border: 1px solid #fcd200;
    border-radius: var(--radius-md);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset;
    transition: background var(--geal-transition);
    white-space: nowrap;
}

.mini-cart-btn:hover {
    background: #f7ca00;
}

.card-link {
    margin-top: 20px;
    font-size: 13px;
    color: var(--geal-info);
    text-decoration: none;
    font-weight: 500;
}

.card-link:hover {
    text-decoration: underline;
    color: var(--geal-accent);
}

/* --- Status Labels --- */

.status-badge {
    color: var(--geal-accent-light);
    font-weight: 700;
}

.status-label {
    font-family: var(--geal-font);
    font-size: 8px;
    font-weight: 900;
    padding: 1px 4px;
    border-radius: 3px;
    text-transform: uppercase;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    line-height: 1;
    letter-spacing: 0.05em;
}

.status-proven {
    background: var(--geal-accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.25);
}

.status-established {
    background: var(--geal-info);
    color: #fff;
}

.status-emerging {
    background: var(--geal-warning);
    color: var(--geal-text-darker);
}

.status-excluded {
    background: var(--geal-danger);
    color: #fff;
}

/* --- Review Stars --- */

.star-rating,
.rating .fa-star,
.review-row .star-rating,
.info-card .rating i,
span.star-rating {
    color: var(--geal-star) !important;
}

/* --- Buy Again Badge --- */

.buy-again-badge {
    position: absolute;
    bottom: 5px;
    left: 5px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--geal-accent);
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 2px;
    font-weight: bold;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--geal-accent);
}

/* --- Badges & Rank Wrapper --- */

.badges-and-rank-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding-top: 4px;
    height: 32px;
    flex-wrap: nowrap;
}

.cert-marks-container {
    display: flex;
    gap: 6px;
    align-items: center;
}

.cert-icon-wrapper {
    width: 32px;
    height: 32px;
    background: var(--geal-bg-card);
    border: 1px solid var(--geal-border);
    border-radius: var(--geal-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.cert-icon-wrapper img {
    height: 28px;
    width: auto;
    object-fit: contain;
}

/* --- GEAL Trust Card --- */

.geal-trust-card {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    background: var(--geal-bg-card);
    border-radius: 10px;
    border: 1px solid var(--geal-border-lighter);
    margin-bottom: 0;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.card-visual-left {
    width: 100px;
    min-width: 100px;
    max-width: 100px;
    flex-shrink: 0;
    position: relative;
    background: var(--geal-bg-warm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-visual-left img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    display: block;
}

.card-content-right {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.trust-card-info {
    flex: 1;
    min-width: 0;
}

.trust-card-cert-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.7rem;
    color: var(--geal-accent);
    font-weight: 600;
    margin-top: 2px;
}

.trust-card-cert-badge i {
    font-size: 0.65rem;
}

.geal-trust-card .store-name {
    font-size: 0.72rem;
    color: var(--geal-text-muted);
    margin: 0;
    display: flex;
    align-items: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.geal-trust-card.favorite-card-removing {
    opacity: 0;
    transform: scale(0.95);
    transition: opacity var(--geal-transition-smooth), transform var(--geal-transition-smooth);
    pointer-events: none;
}

/* --- Favorites Grid --- */

.favorites-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding: 16px;
}

.favorites-grid .info-card {
    width: 100%;
    margin-bottom: 0;
}

.favorite-card {
    background: var(--geal-bg-card);
    border-radius: var(--geal-radius-md);
    overflow: hidden;
    box-shadow: var(--geal-shadow-sm);
    display: flex;
    flex-direction: column;
    position: relative;
    transition: transform var(--geal-transition);
}

.favorite-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.fav-img-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--geal-bg-secondary);
}

.fav-img-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--geal-text-faint);
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: color var(--geal-transition);
}

.remove-btn:hover {
    color: var(--geal-danger);
}

.fav-info {
    padding: 12px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.fav-brand {
    font-size: 10px;
    color: var(--geal-text-muted);
    margin: 0 0 4px 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.fav-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--geal-text-primary-full);
    margin: 0 0 8px 0;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
    box-orient: vertical;
    overflow: hidden;
    flex-grow: 1;
}

.fav-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--geal-text-primary);
    margin: 0 0 12px 0;
}

.add-to-cart-btn {
    background-color: var(--geal-accent);
    color: white;
    border: none;
    padding: 8px;
    border-radius: var(--geal-radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: background-color var(--geal-transition);
}

.add-to-cart-btn:hover {
    background-color: var(--geal-accent-hover);
}

.geal-btn {
    background: var(--geal-gradient-accent);
    color: white;
    border-radius: var(--geal-radius-pill);
    font-weight: 600;
    transition: opacity var(--geal-transition);
}

/* =============================================
   Product Cards - Responsive
   ============================================= */

@media (max-width: 767px) {
    .dashboard-grid-section {
        display: flex;
        flex-direction: column;
        gap: 0;
        padding: 4px;
    }

    .info-card {
        display: flex;
        flex-direction: column;
        padding: 4px;
        overflow: visible;
        background: var(--geal-bg-card);
        border-radius: var(--geal-radius-md);
        box-shadow: var(--geal-shadow-sm);
    }

    .info-card h3 {
        padding: 0 0 6px 0;
        margin: 0;
        font-size: 1rem;
        font-weight: 700;
    }

    .grid-2x2 {
        display: grid;
        grid-template-rows: 1fr;
        grid-auto-flow: column;
        grid-auto-columns: 120px;
        grid-template-columns: unset;
        gap: 6px;
        padding: 0 4px 6px 4px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        scroll-snap-type: x mandatory;
    }

    .grid-2x2::-webkit-scrollbar {
        display: none;
    }

    .card-link {
        padding: 1px 6px 2px 6px;
        font-size: 10px;
    }

    .product-item {
        display: flex;
        flex-direction: column;
        width: 100%;
        min-width: 0;
        max-width: none;
        flex-shrink: 0;
        scroll-snap-align: start;
        background: var(--geal-bg-card);
        border-radius: 6px;
        overflow: hidden;
        border: 1px solid var(--geal-border-lighter);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
        transition: transform var(--geal-transition);
    }

    .product-item:active {
        transform: scale(0.98);
    }

    .product-image-container {
        width: 100%;
        aspect-ratio: 1 / 1;
        position: relative;
        overflow: hidden;
        background: var(--geal-bg-warm);
    }

    .product-item > img,
    .product-item .main-img,
    .product-item .product-image-container > img {
        width: 100%;
        /* 常に正方形に固定。height:100% だとカード(テキスト枠)が高くなった時に
           画像まで縦に伸びて見えるため aspect-ratio で固定する。 */
        aspect-ratio: 1 / 1;
        height: auto;
        max-width: 100%;
        object-fit: cover;
        display: block;
    }

    .item-overlay {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
        color: white;
        padding: 8px;
        font-size: 11px;
        text-align: center;
        font-weight: 600;
    }

    .badges-row {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 3px;
        padding: 3px 4px;
        min-height: 22px;
        background: rgba(0, 0, 0, 0.02);
        border-bottom: 1px solid var(--geal-border-light);
        flex-wrap: nowrap;
        overflow: hidden;
    }

    .cert-marks,
    .cert-marks-container {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 4px;
        flex: 0 0 auto;
    }

    .badges-row img,
    .cert-marks img,
    .cert-icon-wrapper img,
    .level-badge-area img {
        width: auto;
        height: 24px;
        max-width: 32px;
        max-height: 24px;
        object-fit: contain;
        display: block;
    }

    .cert-icon-wrapper {
        width: auto;
        height: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .status-label {
        font-size: 9px;
        padding: 2px 6px;
        border-radius: 3px;
        white-space: nowrap;
        line-height: 1.2;
        flex-shrink: 0;
    }

    .minimal-overlay {
        /* 下だけ少し余白を足してカードを下に伸ばす (価格が下端スレスレだったため) */
        padding: 4px 4px 9px 4px;
        display: flex;
        flex-direction: column;
        gap: 2px;
        flex: 1;
    }

    .product-title,
    .minimal-overlay .item-name {
        font-size: 0.7rem;
        line-height: 1.3;
        margin: 0;
        overflow: hidden;
        /* モバイルでも 2 行まで表示し「…」で省略 (1 行 nowrap だと商品名が途中で切れる) */
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        line-clamp: 2;
        box-orient: vertical;
        white-space: normal;
        word-break: break-word;
        overflow-wrap: anywhere;
        min-height: 2.6em; /* 2 行ぶんの高さを確保し 2 行目の見切れ/価格との衝突を防ぐ */
        color: var(--geal-text-secondary);
        font-weight: 500;
    }

    .minimal-overlay h4 {
        font-size: 0.7rem;
        line-height: 1.3;
        margin: 0;
        overflow: hidden;
        white-space: normal;
        word-break: break-word;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        line-clamp: 2;
        color: var(--geal-text-secondary);
        font-weight: 500;
    }

    .price-cert-row {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 3px;
        margin-top: 3px;
    }

    .inline-cert-img {
        height: 13px;
        width: auto;
    }

    .inline-status-badge {
        font-size: 8px;
        padding: 1px 3px;
    }

    .geal-img-discount-badge {
        font-size: 9px;
        padding: 2px 4px;
        top: 4px;
        right: 4px;
    }

    .geal-rank-badge {
        font-size: 16px;
        top: 3px;
        left: 3px;
    }

    .price-row {
        display: flex;
        flex-direction: column;
        gap: 2px;
        margin-top: 4px;
    }

    .main-price {
        font-size: 0.85rem;
        font-weight: 700;
        color: var(--geal-price);
        line-height: 1.2;
    }

    .geal-trust-card {
        max-width: 100%;
    }

    .card-content-right {
        padding: 8px 10px;
    }

    .product-title {
        font-size: 0.8rem;
        margin-bottom: 4px;
    }

    .favorites-grid {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 16px;
    }

    .favorite-card {
        display: flex;
        flex-direction: row;
        min-height: 140px;
    }

    .fav-img-container {
        width: 140px;
        min-width: 140px;
        aspect-ratio: 1;
    }

    .fav-info {
        flex: 1;
        padding: 16px;
    }

    .fav-name {
        font-size: 0.95rem;
        -webkit-line-clamp: 3;
        line-clamp: 3;
    }

    .fav-price {
        font-size: 1.1rem;
        margin: 8px 0 12px 0;
    }

    .mini-cart-btn,
    .add-to-cart-btn,
    .remove-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
        font-size: 15px;
    }

    h2.section-title,
    .section-title {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
    .favorites-grid {
        gap: 12px;
        padding: 12px;
    }
}

@media (max-width: 375px) {
    .grid-2x2 .product-item {
        width: 100%;
        min-width: 0;
        max-width: none;
    }

    .product-title,
    .minimal-overlay h4,
    .minimal-overlay .item-name {
        font-size: 0.8rem;
    }

    .main-price {
        font-size: 1rem;
    }

    .badges-row img,
    .cert-marks img,
    .cert-icon-wrapper img,
    .level-badge-area img {
        height: 20px;
        max-height: 20px;
    }

    .status-label {
        font-size: 8px;
        padding: 2px 4px;
    }

    .info-card h3 {
        font-size: 1rem;
        padding: 0 12px 10px 12px;
    }

    .grid-2x2 {
        padding: 0 12px 12px 12px;
    }

    .card-link {
        padding: 0 12px 6px 12px;
        font-size: 12px;
    }
}

@media (min-width: 376px) and (max-width: 767px) {
    .grid-2x2 .product-item {
        width: 100%;
        min-width: 0;
        max-width: none;
    }

    .product-title,
    .minimal-overlay h4,
    .minimal-overlay .item-name {
        font-size: 0.9rem;
    }

    .main-price {
        font-size: 0.9rem;
    }

    .badges-row img,
    .cert-marks img,
    .cert-icon-wrapper img,
    .level-badge-area img {
        height: 26px;
        max-height: 26px;
        max-width: 36px;
    }

    .status-label {
        font-size: 10px;
    }

    .info-card h3 {
        font-size: 1.15rem;
    }
}

/* PC/タブレット/大型PCの列数は基底定義（@min:768/1024/1440）で完結。 */

/* =============================================
   Dark Mode overrides for product-cards
   ============================================= */

/* ---- Dashboard section labels ---- */
[data-theme="dark"] .dashboard-grid-section > h3,
[data-theme="dark"] .dashboard-grid-section .dashboard-section > h3 {
    color: var(--geal-text-primary) !important;
}

/* ---- Cart summary area ---- */
[data-theme="dark"] .cart-summary-area {
    background: var(--geal-bg-secondary) !important;
}

[data-theme="dark"] .cart-summary-area span,
[data-theme="dark"] .cart-summary-area p {
    color: var(--geal-text-secondary) !important;
}

[data-theme="dark"] .cart-summary-area #subtotal,
[data-theme="dark"] .cart-summary-area #cart-total,
[data-theme="dark"] .cart-summary-area #cart-payment-due-value {
    color: var(--geal-price) !important;
}

[data-theme="dark"] .cart-summary-area #cart-shipping-cost {
    color: var(--geal-text-primary) !important;
}

[data-theme="dark"] .cart-summary-area #cart-total-row {
    border-top-color: var(--geal-border) !important;
}

[data-theme="dark"] .cart-summary-area #cart-points-use-section,
[data-theme="dark"] .cart-summary-area #cart-points-rebate,
[data-theme="dark"] .cart-summary-area #cart-core-rebate,
[data-theme="dark"] .cart-summary-area #cart-payment-due {
    border-color: var(--geal-border) !important;
}

[data-theme="dark"] .cart-summary-area #cart-points-use-input {
    background: var(--geal-bg-muted) !important;
    border-color: var(--geal-border-muted) !important;
    color: var(--geal-text-primary) !important;
}

[data-theme="dark"] .cart-summary-area .cart-summary-area span[style*="font-weight: 600"],
[data-theme="dark"] .cart-summary-area span[style*="font-weight: 700"] {
    color: inherit !important;
}

/* Impact block */
[data-theme="dark"] #cart-impact-block {
    background: rgba(34, 197, 94, 0.12) !important;
    border-color: rgba(34, 197, 94, 0.3) !important;
}

[data-theme="dark"] #cart-impact-message {
    color: var(--geal-success-light) !important;
}

/* Large purchase bonus */
[data-theme="dark"] #cart-large-purchase-bonus-wrap {
    background: var(--geal-gradient-warning) !important;
    border-color: var(--geal-warning-deep) !important;
}

[data-theme="dark"] #cart-large-purchase-bonus-message {
    color: var(--geal-warning) !important;
}

/* no-data-msg */
[data-theme="dark"] .no-data-msg {
    color: var(--geal-text-muted) !important;
}

/* Repair section on product detail */
[data-theme="dark"] #product-repair-section {
    background: var(--geal-bg-secondary) !important;
    border-color: var(--geal-border) !important;
}
