/* =============================================================================
   style-compare.css — مقایسه کالا و خدمات
   -----------------------------------------------------------------------------
   ساختار ستونی است: هر کالا یک ستون و هر ویژگی یک سطر. ستون نخست (نام ویژگی)
   چسبیده می‌ماند و بقیه ستون‌ها با اسکرول افقی دیده می‌شوند — در موبایل و
   دسکتاپ یکسان کار می‌کند و ستون‌ها همیشه کنار هم می‌مانند.
   ========================================================================== */

.cmp-wrap { padding: 15px; }

/* --- سربرگ صفحه --- */
.cmp-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; margin-bottom: 14px; flex-wrap: wrap;
}
.cmp-head h1 { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.cmp-head h1 i { color: var(--primary); }
.cmp-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- هشدارها --- */
.cmp-alert {
    display: flex; align-items: flex-start; gap: 8px; border-radius: 12px;
    padding: 10px 12px; font-size: 12px; line-height: 1.9; margin-bottom: 12px;
}
.cmp-alert.warn { background: #fff5e5; color: #8a5a00; }
.cmp-alert.info { background: #eef3fb; color: #22456e; }
.cmp-alert.ok { background: #e8f6ef; color: #14724c; }
.cmp-alert.error { background: #fdecec; color: #a02020; }
.cmp-alert i { margin-top: 3px; flex-shrink: 0; }

/* --- دکمه‌ها --- */
.cmp-btn {
    border: none; border-radius: 11px; padding: 9px 15px; cursor: pointer;
    background: var(--primary); color: #fff; font-family: inherit;
    font-size: 12.5px; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.cmp-btn.ghost { background: var(--light); color: var(--text); }
.cmp-btn.danger { background: #fdecec; color: #a02020; }
.cmp-btn.block { width: 100%; }
.cmp-btn:disabled { background: #c9ced6; cursor: not-allowed; }
.cmp-btn.on { background: #22a06b; }

/* =============================================================================
   جدول مقایسه
   ========================================================================== */

.cmp-scroll {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 3px 14px rgba(0,0,0,.05);
}
.cmp-scroll::-webkit-scrollbar { height: 7px; }
.cmp-scroll::-webkit-scrollbar-thumb { background: #cfd5dd; border-radius: 4px; }
.cmp-scroll::-webkit-scrollbar-track { background: transparent; }

.cmp-table {
    border-collapse: separate;
    border-spacing: 0;
    width: max-content;
    min-width: 100%;
    font-size: 12.5px;
}

/* --- ستون نخست: نام ویژگی، چسبیده به راست --- */
.cmp-table th.cmp-key,
.cmp-table td.cmp-key {
    position: sticky;
    right: 0;
    z-index: 3;
    background: var(--white);
    width: 118px;
    min-width: 118px;
    text-align: right;
    font-weight: 600;
    color: var(--gray);
    padding: 11px 12px;
    border-inline-end: 1px solid #eceff3;
    box-shadow: -3px 0 8px -4px rgba(0,0,0,.12);
}

/* --- ستون هر کالا --- */
.cmp-table th.cmp-col,
.cmp-table td.cmp-col {
    width: 190px;
    min-width: 190px;
    max-width: 190px;
    padding: 11px 12px;
    text-align: center;
    vertical-align: middle;
    border-bottom: 1px solid #f2f4f6;
    scroll-snap-align: start;
}
.cmp-table tbody tr:hover td { background: #fafbfc; }
.cmp-table tbody tr:hover td.cmp-key { background: #f6f8fa; }

/* --- سر جدول: کارت کالا --- */
.cmp-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--white);
    border-bottom: 2px solid #eceff3;
    padding: 12px;
}
.cmp-table thead th.cmp-key { z-index: 4; }

.cmp-card { position: relative; text-align: center; }
.cmp-card-remove {
    position: absolute; top: -4px; left: -4px; z-index: 2;
    width: 24px; height: 24px; border: none; border-radius: 50%;
    background: #fdecec; color: #a02020; cursor: pointer; font-size: 11px;
}
.cmp-card > a > img {
    width: 84px; height: 84px; object-fit: contain;
    margin: 0 auto 8px; border-radius: 10px; background: var(--light);
}
.cmp-card h4 {
    font-size: 12.5px; font-weight: 600; line-height: 1.7; margin-bottom: 6px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; min-height: 42px;
}

/* --- نشان فروشگاه روی کارت --- */
.cmp-card-shop {
    display: inline-flex; align-items: center; gap: 5px;
    background: var(--light); border-radius: 8px;
    padding: 4px 8px; margin-bottom: 7px;
    font-size: 10.5px; color: var(--gray); max-width: 100%;
}
.cmp-card-shop img { width: 16px; height: 16px; border-radius: 4px; object-fit: cover; }
.cmp-card-shop span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cmp-card-price { font-size: 13.5px; font-weight: 700; margin-bottom: 3px; }
.cmp-card-price del { display: block; font-size: 10.5px; color: var(--gray); font-weight: 400; }
.cmp-card-off {
    display: inline-block; background: var(--primary); color: #fff;
    font-size: 10px; padding: 2px 7px; border-radius: 6px; margin-bottom: 7px;
}

.cmp-card-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.cmp-card-actions .cmp-btn { padding: 8px 10px; font-size: 11.5px; }

/* --- نشان‌های برتری --- */
.cmp-tag {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 10px; padding: 2px 7px; border-radius: 6px; margin-bottom: 6px;
}
.cmp-tag.cheap { background: #e8f6ef; color: #14724c; }
.cmp-tag.top { background: #fff5e5; color: #8a5a00; }

/* --- سر گروه ویژگی‌ها --- */
/* سلول تمام‌عرض است، پس sticky روی خودش اثری ندارد؛ عنوان را داخل یک
   span چسبان می‌گذاریم تا هنگام اسکرول افقی همیشه دیده شود. */
.cmp-table tr.cmp-group td {
    background: #f5f7fa;
    padding: 0;
    border-top: 1px solid #e6eaee;
    border-bottom: 1px solid #e6eaee;
}
.cmp-group-title {
    position: sticky;
    right: 0;
    display: inline-block;
    padding: 9px 12px;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text);
}
.cmp-group-title i { color: var(--primary); margin-inline-end: 6px; }

/* --- مقدارها --- */
.cmp-val { line-height: 1.8; word-break: break-word; }
.cmp-val.empty { color: #c2c8d0; }
.cmp-val.best { color: #14724c; font-weight: 700; }
.cmp-val.best::after {
    content: '\f00c'; font-family: 'Font Awesome 6 Free'; font-weight: 900;
    font-size: 9px; margin-inline-start: 5px;
}

/* سطرهایی که مقدارشان یکسان است — با کلید «فقط تفاوت‌ها» پنهان می‌شوند */
.cmp-table.diff-only tr.cmp-same { display: none; }

/* --- حالت خالی --- */
.cmp-empty { text-align: center; padding: 45px 20px; }
.cmp-empty i { font-size: 52px; color: #d8dde4; margin-bottom: 14px; }
.cmp-empty h3 { font-size: 15px; margin-bottom: 8px; }
.cmp-empty p { font-size: 12.5px; color: var(--gray); line-height: 1.9; margin-bottom: 18px; }

/* --- راهنمای اسکرول --- */
.cmp-scroll-hint {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    font-size: 11px; color: var(--gray); padding: 8px 0 0;
}
.cmp-scroll-hint i { animation: cmpSwipe 1.6s ease-in-out infinite; }
@keyframes cmpSwipe {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-6px); }
}

/* =============================================================================
   مودال مقایسه
   ========================================================================== */

.cmp-modal {
    position: fixed; inset: 0; z-index: 1200;
    display: none; align-items: flex-end; justify-content: center;
    background: rgba(0,0,0,.5);
}
.cmp-modal.active { display: flex; }

.cmp-modal-box {
    background: var(--light);
    width: 100%; max-width: 600px;
    max-height: 92vh;
    border-radius: 18px 18px 0 0;
    display: flex; flex-direction: column;
    animation: cmpUp .25s ease;
}
@keyframes cmpUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.cmp-modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 15px; background: var(--white);
    border-radius: 18px 18px 0 0; border-bottom: 1px solid #eceff3;
}
.cmp-modal-head h3 { font-size: 14.5px; font-weight: 700; display: flex; align-items: center; gap: 7px; }
.cmp-modal-head h3 i { color: var(--primary); }
.cmp-modal-close {
    border: none; background: var(--light); cursor: pointer;
    width: 30px; height: 30px; border-radius: 50%; color: var(--gray); font-size: 14px;
}

.cmp-modal-body { overflow-y: auto; padding: 14px 15px; flex: 1; }

.cmp-modal-foot {
    padding: 12px 15px; background: var(--white);
    border-top: 1px solid #eceff3; display: flex; gap: 9px;
}
.cmp-modal-foot > * { flex: 1; }

/* --- نوار شناور تعداد کالاهای مقایسه --- */
.cmp-fab {
    position: fixed; bottom: 84px; inset-inline-start: 15px; z-index: 900;
    display: none; align-items: center; gap: 8px;
    background: var(--dark); color: #fff;
    border: none; border-radius: 30px; padding: 11px 17px; cursor: pointer;
    font-family: inherit; font-size: 12.5px; font-weight: 600;
    box-shadow: 0 5px 18px rgba(0,0,0,.25);
}
.cmp-fab.visible { display: inline-flex; }
.cmp-fab .count {
    background: var(--primary); color: #fff;
    min-width: 21px; height: 21px; line-height: 21px;
    border-radius: 50%; font-size: 11px; text-align: center;
}

/* --- دکمه مقایسه روی کارت کالا در فهرست فروشگاه --- */
.p-card-img { position: relative; }
.p-compare-btn {
    position: absolute; bottom: 7px; inset-inline-start: 7px; z-index: 2;
    width: 27px; height: 27px; border: none; border-radius: 50%;
    background: rgba(255,255,255,.92); color: var(--gray);
    cursor: pointer; font-size: 11px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 7px rgba(0,0,0,.12); transition: .2s;
}
.p-compare-btn:hover { color: var(--primary); transform: scale(1.1); }
.p-compare-btn.active { background: var(--primary); color: #fff; }

/* در دسکتاپ ستون‌ها کمی پهن‌تر می‌شوند چون فضا هست */
@media (min-width: 700px) {
    .cmp-table th.cmp-col,
    .cmp-table td.cmp-col { width: 230px; min-width: 230px; max-width: 230px; }
    .cmp-table th.cmp-key,
    .cmp-table td.cmp-key { width: 150px; min-width: 150px; }
    .cmp-modal-box { border-radius: 18px; max-height: 88vh; }
    .cmp-modal { align-items: center; }
    .cmp-modal-head { border-radius: 18px 18px 0 0; }
}
