/* Amazon-1688 Research Tool - Minimal CSS */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--gray-900);
    background: var(--gray-50);
    line-height: 1.6;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 1rem; }

/* Navbar */
.navbar {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    padding: .75rem 0;
}
.nav-container { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }
.nav-brand { font-weight: 700; color: var(--gray-900); text-decoration: none; font-size: 1.1rem; }
.nav-links { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.nav-links a { color: var(--gray-700); text-decoration: none; font-size: .9rem; }
.nav-links a:hover { color: var(--primary); }
.nav-admin { color: var(--primary) !important; font-weight: 600; }
.nav-user { color: var(--gray-500); font-size: .85rem; }
.nav-separator { color: var(--gray-300); font-size: .85rem; }

/* Main */
main { padding: 1.5rem 0 3rem; }
h1 { font-size: 1.5rem; margin-bottom: 1rem; }
h2 { font-size: 1.2rem; margin-bottom: .75rem; }

/* Cards */
.card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 1.25rem; }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
.stat-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: .85rem; color: var(--gray-500); margin-top: .25rem; }

/* Buttons */
.btn {
    display: inline-block;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    font-size: .9rem;
    text-decoration: none;
    transition: background .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; border-color: var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-100); }
.btn-full { width: 100%; text-align: center; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }

/* Forms */
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.form-row .form-group { flex: 1; min-width: 150px; margin-bottom: .5rem; }
.create-user-form .form-group { margin-bottom: .5rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: .3rem; font-weight: 500; font-size: .9rem; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: .95rem;
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}
.form-group small { color: var(--gray-500); font-size: .8rem; }
.input-sm { width: 80px; padding: .3rem .5rem; font-size: .85rem; border: 1px solid var(--gray-300); border-radius: var(--radius); }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--gray-200); }
.table th { background: var(--gray-100); font-weight: 600; font-size: .85rem; color: var(--gray-700); }
.table tr:hover { background: var(--gray-50); }
.table tr.inactive { opacity: .5; }

/* Badges */
.badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}
.badge-admin { background: #dbeafe; color: #1e40af; }
.badge-member { background: var(--gray-100); color: var(--gray-700); }
.badge-active, .badge-completed { background: #dcfce7; color: #166534; }
.badge-inactive, .badge-failed { background: #fee2e2; color: #991b1b; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-running { background: #dbeafe; color: #1e40af; }
.badge-stopped { background: #fff3cd; color: #856404; }

/* Alerts */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }

/* Auth */
.auth-container { display: flex; justify-content: center; padding-top: 4rem; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 2rem; }
.auth-card h1 { text-align: center; }
.auth-subtitle { text-align: center; color: var(--gray-500); margin-bottom: 1.5rem; }
.auth-footer { text-align: center; margin-top: 1rem; font-size: .85rem; color: var(--gray-500); }

/* DL horizontal */
.dl-horizontal { display: grid; grid-template-columns: 140px 1fr; gap: .4rem 1rem; }
.dl-horizontal dt { font-weight: 600; color: var(--gray-700); font-size: .9rem; }
.dl-horizontal dd { font-size: .9rem; }
/* スマホ: ラベル列を詰めて「モード ⇔ 値」の間延びを解消（2026-08-11） */
@media (max-width: 640px) {
    .dl-horizontal { grid-template-columns: 88px 1fr; gap: .45rem .6rem; align-items: start; }
    .dl-horizontal dt { font-size: .85rem; padding-top: 2px; }
}

/* Progress bar */
.progress-bar { height: 20px; background: var(--gray-200); border-radius: 10px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); color: #fff; font-size: .75rem; line-height: 20px; text-align: center; transition: width .5s; }

/* Utility */
.mt-1 { margin-top: 1rem; }
.text-muted { color: var(--gray-500); font-size: .85rem; }
.monospace { font-family: monospace; font-size: .85rem; word-break: break-all; }
.inline-form { display: inline-flex; align-items: center; gap: .5rem; margin-right: 1rem; margin-bottom: .5rem; }
.action-group { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.admin-nav { display: flex; gap: .75rem; margin-top: 1.5rem; }
.error-log { background: var(--gray-100); padding: 1rem; border-radius: var(--radius); font-size: .85rem; overflow-x: auto; white-space: pre-wrap; }

/* AI Chat - Clean Simple Design */
.ai-chat-container {
    max-height: 480px;
    overflow-y: auto;
    padding: .5rem 0;
    margin-bottom: .75rem;
    scroll-behavior: smooth;
}

.ai-chat-message {
    display: flex;
    gap: .6rem;
    margin-bottom: .75rem;
    align-items: flex-start;
}

.ai-chat-user {
    flex-direction: row-reverse;
}

.ai-chat-avatar {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .7rem;
    font-weight: 700;
    color: #fff;
}

.ai-avatar-ai { background: var(--primary); }
.ai-avatar-you { background: var(--gray-500); }

.ai-chat-bubble {
    max-width: 80%;
    padding: .65rem .9rem;
    border-radius: 12px;
    font-size: .9rem;
    line-height: 1.65;
    word-break: break-word;
}

.ai-chat-assistant .ai-chat-bubble {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 2px 12px 12px 12px;
    color: var(--gray-900);
}

.ai-chat-user .ai-chat-bubble {
    background: var(--primary);
    color: #fff;
    border-radius: 12px 12px 2px 12px;
}

/* Input */
.ai-chat-input-area {
    padding-top: .5rem;
    border-top: 1px solid var(--gray-200);
}

.ai-chat-input {
    flex: 1;
    padding: .55rem .75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: .95rem;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    min-height: 44px;
    max-height: 140px;
    overflow-y: auto;
}

.ai-chat-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,.12);
}

.ai-chat-send-btn {
    flex-shrink: 0;
    height: 40px;
    padding: 0 1.1rem;
    align-self: flex-end;
}

/* Keyword buttons in chat */
.ai-chat-keyword-btn {
    margin-left: .25rem;
    vertical-align: middle;
}

.ai-chat-kw-name {
    color: var(--primary);
    font-weight: 600;
    font-size: .92rem;
}

.ai-chat-kw-name.kw-warn {
    color: #dc3545;
}

.ai-chat-kw-name.kw-ng {
    color: #0d6efd;
}

.ai-chat-kw-row.kw-warn-row {
    opacity: 0.7;
}

.ai-chat-kw-row.kw-ng-row {
    opacity: 0.7;
}

/* Typing dots */
.ai-chat-loading {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: .15rem 0;
}

.ai-chat-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    opacity: .4;
    animation: ai-dot-bounce .6s ease-in-out infinite;
}

.ai-chat-dot:nth-child(2) { animation-delay: .15s; }
.ai-chat-dot:nth-child(3) { animation-delay: .3s; }

@keyframes ai-dot-bounce {
    0%, 100% { transform: translateY(0); opacity: .3; }
    50% { transform: translateY(-5px); opacity: 1; }
}

@media (max-width: 600px) {
    .ai-chat-container { max-height: 350px; }
    .ai-chat-bubble { max-width: 88%; font-size: .85rem; }
}

/* Keyword Expansion */
.ai-chat-kw-row {
    display: inline;
}

.ai-chat-expand-btn {
    background: #fff;
    border: 1.5px solid #e65100;
    color: #e65100;
    font-weight: 600;
    margin-left: .25rem;
    vertical-align: middle;
}

.ai-chat-expand-btn:hover {
    background: #fff3e0;
}

.ai-chat-expand-btn:disabled {
    opacity: .6;
    cursor: wait;
}

.kw-expand-result {
    display: block;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: .5rem .75rem;
    margin-top: .4rem;
    margin-bottom: .4rem;
}

.kw-expand-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .25rem 0;
}

.kw-expand-item:not(:last-child) {
    border-bottom: 1px solid var(--gray-200);
}

.kw-expand-item .ai-chat-kw-name {
    flex: 1;
    min-width: 0;
}

/* Discovery toast notification */
.discovery-toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    pointer-events: none;
}

.discovery-toast {
    background: linear-gradient(135deg, #16a34a, #15803d);
    color: #fff;
    padding: .75rem 1.25rem;
    border-radius: 10px;
    font-size: .95rem;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(22, 163, 74, .35);
    animation: toast-slide-in .4s ease-out, toast-fade-out .5s ease-in 2.5s forwards;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.discovery-toast-icon {
    font-size: 1.3em;
}

@keyframes toast-slide-in {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toast-fade-out {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* Footer */
.footer { border-top: 1px solid var(--gray-200); padding: 1rem 0; margin-top: 2rem; color: var(--gray-500); font-size: .8rem; text-align: center; }


/* ==========================================================================
   モバイル対応 (CSS-only / PC表示は一切変更なし)
   2026-05-05 追加: スマホで PC 同等の操作ができるよう @media クエリで上書き
   - 769px 以上は既存スタイルそのまま
   - 768px 以下でレイアウト・余白・タッチサイズを最適化
   ========================================================================== */

@media (max-width: 768px) {
    /* ── 全体: コンテナ余白を詰める ── */
    .container { padding: 0 .5rem; }
    body { font-size: 14px; }

    /* ── Navbar: ロゴ縮小、ユーザー情報を折り返し、下段ナビは横スクロール ── */
    .navbar { padding: .5rem 0; }
    .navbar .nav-brand img { height: 80px !important; }
    .navbar .container > div:first-child {
        flex-wrap: wrap !important;
        gap: .35rem !important;
        margin-bottom: .35rem !important;
    }
    .navbar .container > div:first-child > div:last-child {
        width: 100%;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: .35rem !important;
        font-size: .72rem !important;
    }
    /* 下段メインナビ4-7項目を横スクロール対応（インラインstyle 上書き） */
    .navbar > .container > div:last-of-type {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        padding: .35rem 0 .5rem 0 !important;
        gap: .35rem !important;
        scrollbar-width: thin;
        /* スクロール出来ることを示すフェードグラデ */
        mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 24px), transparent);
        -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 24px), transparent);
    }
    .navbar > .container > div:last-of-type > * {
        flex-shrink: 0 !important;
        padding: .45rem .75rem !important;
        font-size: .82rem !important;
        white-space: nowrap !important;
    }
    .navbar > .container > div:last-of-type > span {
        padding: 0 !important;
        margin: 0 .15rem !important;
    }

    /* ── 見出し ── */
    h1 { font-size: 1.35rem; line-height: 1.3; margin-bottom: .65rem; }
    h2 { font-size: 1.15rem; }
    h3 { font-size: 1rem; }

    /* ── テーブル: 親に overflow-x: auto がある前提でスクロール、文字を小さく ── */
    .table { font-size: .76rem; }
    .table th, .table td {
        padding: .4rem .35rem !important;
        word-break: break-word;
    }
    /* 親要素を強制的にスクロール可能に（はみ出し防止） */
    .table-container, .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* ── フォーム: iOS の自動ズーム回避 + 縦並び ── */
    input[type="text"], input[type="number"], input[type="email"],
    input[type="password"], input[type="search"], input[type="url"],
    textarea, select {
        font-size: 16px !important;  /* iOS Safari で 16px 未満だと focus 時にズームされる */
    }
    .form-group { margin-bottom: .65rem; }
    .form-row { flex-direction: column; gap: .5rem; }
    .form-row .form-group { width: 100%; min-width: 0; flex: 1 1 100%; }

    /* ── ボタン: タッチターゲットを最低 40px 確保 ── */
    .btn { padding: .6rem 1rem; min-height: 42px; font-size: .9rem; }
    .btn-sm { padding: .4rem .7rem; min-height: 34px; font-size: .82rem; }

    /* ── カード: 余白を詰める ── */
    .card { padding: .85rem; border-radius: 8px; margin-bottom: .75rem; }
    .auth-card { padding: 1.25rem; max-width: 100%; }

    /* ── 認証ページのレイアウト ── */
    .auth-page { padding: 1rem; min-height: auto; }

    /* ── 出品準備シート / バリエーション設定 のアクションバー: 折り返し有効化 ── */
    /* インラインスタイルで display:flex を持つ要素は折り返しを許可 */
    [style*="display: flex"][style*="gap"]:not(.no-mobile-wrap) {
        flex-wrap: wrap !important;
    }

    /* ── 候補一覧 (惜しい商品含む) の横並びコンテナ ── */
    [style*="overflow-x: auto"] { -webkit-overflow-scrolling: touch; }

    /* ── 数値・URL等の長文テキストは折り返し ── */
    td a, td span { word-break: break-word; }

    /* ── footer ── */
    .footer { font-size: .7rem; padding: .75rem 0 1.5rem; }
}

@media (max-width: 480px) {
    /* スマホ縦持ち（〜iPhone 標準幅）向けのさらに細かい調整 */
    .container { padding: 0 .4rem; }
    .navbar .nav-brand img { height: 64px !important; }
    h1 { font-size: 1.2rem; }
    .table { font-size: .72rem; }
    .table th, .table td { padding: .3rem .25rem !important; }

    /* 上部ナビのリンクをアイコン的に小さく */
    .navbar .container > div:first-child > div:last-child {
        font-size: .68rem !important;
    }
    .navbar .container > div:first-child > div:last-child .btn-sm {
        padding: .3rem .55rem;
        min-height: 30px;
        font-size: .72rem;
    }
}

/* ==========================================================================
   スマホ専用: テーブルをカード表示に切り替える .m-cards
   - PC (>= 769px): クラスは何の効果も持たず、テーブル表示のまま
   - スマホ (<= 768px): tr ごとにカード表示、各 td が「ラベル + 値」の縦並び
   - HTMLには class="m-cards" を <table> に付け、各 <td> に data-label="列名"
   - 画像・タイトルなど横並びにしないセルは class="m-full" で全幅化
   ========================================================================== */
@media (max-width: 768px) {
    /* テーブル全体 */
    table.m-cards {
        display: block;
        width: 100%;
        border-collapse: separate;
        font-size: .85rem;
        min-width: 0 !important;
        table-layout: auto !important;  /* PCで table-layout: fixed が指定されてても解除 */
    }
    /* colgroup の幅指定もスマホでは無効化 */
    table.m-cards colgroup, table.m-cards col { display: none !important; }
    table.m-cards thead { display: none; }
    table.m-cards tbody { display: block; }
    table.m-cards tr {
        display: block;
        background: #fff;
        border: 1px solid #e5e7eb !important;
        border-radius: 10px;
        margin: 0 0 .75rem 0;
        padding: .85rem .9rem;
        box-shadow: 0 1px 3px rgba(0,0,0,.05);
    }
    table.m-cards tr:nth-child(even) { background: #fff !important; }
    table.m-cards td {
        display: block !important;             /* 縦並び（ラベル上 / 入力下） */
        padding: .4rem 0 !important;
        border: none !important;
        border-top: 1px dashed #f3f4f6 !important;
        text-align: left !important;
        width: 100% !important;
        min-width: 0 !important;
    }
    table.m-cards tr td:first-child { border-top: none !important; }
    /* 列ラベル（data-label属性から自動生成）— 入力欄の上に薄く表示 */
    table.m-cards td::before {
        content: attr(data-label);
        display: block;
        font-size: .72rem;
        color: #6b7280;
        font-weight: 600;
        letter-spacing: .02em;
        margin-bottom: .3rem;
        white-space: normal;
        word-break: keep-all;
    }
    /* 入力要素・値は全幅、横並びの上書きを解除 */
    table.m-cards td > * { max-width: 100%; box-sizing: border-box; }
    table.m-cards td input,
    table.m-cards td select,
    table.m-cards td textarea {
        width: 100% !important;
        max-width: 100% !important;
    }
    /* m-full: 画像・タイトル等の全幅セル（縦並びは同じだがラベルを隠す） */
    table.m-cards td.m-full::before { display: none !important; }
    /* 削除ボタンや小さいセルはラベル隠してもOK（ラベルが目立ちすぎる場合）*/
    table.m-cards td[data-label="削除"] {
        text-align: center !important;
    }
    table.m-cards td[data-label="削除"]::before {
        font-size: .68rem;
        margin-bottom: .15rem;
    }
    /* 数量・セット数・販売・元合計などの数値系: 入力欄を右寄せに保つ */
    table.m-cards td input[type="number"],
    table.m-cards td input.var-total {
        text-align: right;
    }

    /* ============== タッチターゲット最適化（40代向けに視認性UP）============== */

    /* チェックボックスを 24x24 に拡大 + クリック領域広め */
    table.m-cards input[type="checkbox"],
    .m-cards input[type="checkbox"] {
        width: 26px !important;
        height: 26px !important;
        cursor: pointer;
        margin: 4px 6px 4px 0 !important;
        accent-color: #1565c0;
    }

    /* SEO の ○/未 を 大きいバッジに */
    table.m-cards td a[id^="seo-status"],
    table.m-cards td span[id^="seo-status"] {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        min-width: 56px !important;
        min-height: 44px !important;
        padding: .55rem 1rem !important;
        font-size: 1.05rem !important;
        font-weight: 700 !important;
        border-radius: 10px !important;
        line-height: 1 !important;
    }

    /* バリエーション列の「✓ 保存済み」/「未設定」リンクを大きく */
    table.m-cards td a[href^="/listing-prep/variations/"] {
        min-height: 56px !important;
        min-width: 96px !important;
        padding: .65rem 1.1rem !important;
        font-size: .95rem !important;
        border-radius: 10px !important;
        gap: 4px !important;
    }

    /* 削除ボタン (出品準備一覧 / 候補一覧 / 惜しい商品 / バリエーション設定) */
    table.m-cards td button[type="submit"],
    table.m-cards td[data-label="操作"] button,
    table.m-cards td[data-label="削除"] button {
        min-height: 48px !important;
        min-width: 80px !important;
        padding: .65rem 1.25rem !important;
        font-size: 1rem !important;
        font-weight: 700 !important;
        border-radius: 8px !important;
        background: #fee2e2 !important;
        color: #dc2626 !important;
        border: 1px solid #fecaca !important;
        cursor: pointer;
    }

    /* 候補一覧の「N件 ▼」「市場調査」など、リンク・ボタン共通の最低タッチサイズ */
    table.m-cards td button,
    table.m-cards td a {
        min-height: 44px;
    }
    /* ただしテキストリンク(商品タイトル等)はサイズ固定しない */
    table.m-cards td.m-full a {
        min-height: 0 !important;
    }

    /* カード自体のパディング（詰めすぎず・間延びしすぎず） */
    table.m-cards tr {
        padding: .8rem .9rem !important;
        margin-bottom: .8rem !important;
    }

    /* 「選択」チェックは1行にまとめてコンパクトに（ラベル左・チェック右） */
    table.m-cards td[data-label="選択"] {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: .5rem;
        padding: .1rem 0 !important;
    }
    table.m-cards td[data-label="選択"]::before {
        margin-bottom: 0 !important;
        display: inline-block !important;
    }

    /* 上部のアクションバー（一括SEO/発注シート/全選択 等）のボタンも大きく */
    body button.btn,
    body a.btn {
        min-height: 46px;
        padding: .65rem 1.1rem;
        font-size: .95rem;
    }
    body button.btn-sm,
    body a.btn-sm {
        min-height: 40px;
        padding: .5rem .8rem;
        font-size: .88rem;
    }
    /* m-hide-mobile: スマホで非表示 */
    table.m-cards td.m-hide-mobile { display: none !important; }

    /* 強制的に表示するために横スクロール親の min-width をリセット */
    table.m-cards { min-width: 0 !important; }

    /* スマホの商品画像: 大きすぎない高さに抑えてスクロール量を削減 */
    table.m-cards td.m-full img {
        width: auto !important;
        height: auto !important;
        max-width: 100% !important;
        max-height: 150px;
        object-fit: contain !important;
        background: #f9fafb;
        border-radius: 8px;
        display: block;
        margin: 0 auto .25rem;
    }

    /* m-detail-row: 候補/惜しい の▼ボタンで開く詳細行をカード下にぶら下げる
       JSが style.display を "table-row" に切り替えるので !important で block に上書き */
    table.m-cards tr.m-detail-row[style*="display: none"] { display: none !important; }
    table.m-cards tr.m-detail-row {
        display: block !important;
        margin-top: -.65rem !important;
        margin-bottom: .85rem !important;
        background: #f0f9ff !important;
        border: 1px solid #bae6fd !important;
        border-radius: 0 0 10px 10px;
        padding: .6rem .65rem !important;
        box-shadow: 0 1px 3px rgba(0,0,0,.05);
    }
    table.m-cards tr.m-detail-row td {
        display: block !important;
        border: none !important;
        padding: 0 !important;
    }
    table.m-cards tr.m-detail-row td::before { display: none !important; }
    /* 詳細行内の横スクロールリストはそのまま機能 */
    table.m-cards tr.m-detail-row [style*="overflow-x: auto"] {
        margin: 0 !important;
        padding-bottom: .35rem !important;
    }

    /* ==============================================================
       上部アクションバー（全選択/移動/SEO/自動収集 等のボタン列）
       スマホでは2列グリッドに整列: ボタンは同じ幅・高さ、
       ステータス文字（0件選択中/収集中…）は全幅で1行にまとめる
       ============================================================== */
    .m-action-bar {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: .5rem !important;
        align-items: stretch !important;
    }
    /* form で包まれたボタン（FBAライバル再計算等）もグリッドの1マスとして扱う */
    .m-action-bar form { display: contents; }
    .m-action-bar button,
    .m-action-bar a.btn {
        width: 100% !important;
        margin: 0 !important;
        box-sizing: border-box;
        min-height: 48px;
        padding: .55rem .5rem !important;
        font-size: .88em !important;
        border-radius: 8px !important;
        line-height: 1.25 !important;
        white-space: normal !important;   /* 長い文言は折り返す */
    }
    /* ステータス表示（0件選択中・収集中…・保存済み等）は全幅・中央 */
    .m-action-bar > span {
        grid-column: 1 / -1;
        text-align: center;
        padding: .05rem 0;
    }
    /* display:none のステータスはグリッドの隙間を作らない（そのまま非表示） */
}
