/* ============================================================
   image-upload.css — الگوی واحد آپلود عکس در کل سایت (accounts_8)
   ============================================================
   همراه static/js/image-upload.js — روی inputهای دارای کلاس
   «js-image-upload» کار می‌کند و این UI را می‌سازد:

   ┌────────────────────────────┐
   │  [پیش‌نمایش عکس + دکمه حذف]  │  ← img-upload__card
   └────────────────────────────┘
   ┌────────────────────────────┐
   │   ⬆ انتخاب یا رها کردن عکس   │  ← img-upload__dropzone
   └────────────────────────────┘

   پیشوند همهٔ کلاس‌ها img-upload است تا با CSS صفحات تداخل نکند.
   ============================================================ */

.img-upload { margin: 6px 0; }

/* حالت فشرده — inline کنار ردیف‌های شلوغ (مثل پوستر ویدیو در فرم محصول) */
.img-upload--compact { display: inline-block; vertical-align: middle; max-width: 300px; margin: 0; }
.img-upload--compact .img-upload__previews { margin-bottom: 6px; }

/* نکته: input اصلی را image-upload.js مخفی می‌کند (نه CSS) تا اگر
   جاوااسکریپت لود نشد، فیلد بومی مرورگر همچنان کار کند. */

/* ===== ناحیهٔ انتخاب (dropzone) ===== */
.img-upload__dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
    padding: 22px 16px;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
    border: 2px dashed #c7d2fe;
    border-radius: 14px;
    cursor: pointer;
    text-align: center;
    font-family: 'Vazir', sans-serif;
    transition: border-color .2s ease, background .2s ease, transform .15s ease;
    -webkit-tap-highlight-color: transparent;
}
.img-upload__dropzone:hover,
.img-upload__dropzone:focus-visible {
    border-color: #6366f1;
    background: #e0e7ff;
    outline: none;
}
.img-upload__dropzone:active { transform: scale(0.99); }

.img-upload__dropzone.is-dragover {
    border-color: #4f46e5;
    background: #c7d2fe;
    border-style: solid;
}
.img-upload__dropzone.is-error {
    border-color: #dc2626;
    background: #fef2f2;
}

.img-upload__dz-icon {
    width: 34px;
    height: 34px;
    color: #6366f1;
    flex: none;
}

.img-upload__dz-text {
    font-size: 0.92rem;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.8;
}
.img-upload__dz-text strong { color: #4338ca; }

.img-upload__dz-hint {
    font-size: 0.75rem;
    color: #64748b;
    line-height: 1.8;
}

/* حالت فشرده (مثلاً پوستر ویدیو کنار ردیف اطلاعات) */
.img-upload__dropzone--compact { padding: 10px 14px; flex-direction: row; gap: 10px; }
.img-upload__dropzone--compact .img-upload__dz-icon { width: 22px; height: 22px; }
.img-upload__dropzone--compact .img-upload__dz-text { font-size: 0.82rem; }
.img-upload__dropzone--compact .img-upload__dz-hint { display: none; }

/* وقتی عکسی انتخاب شده، dropzone خودکار جمع‌وجور می‌شود */
.img-upload__dropzone--mini { padding: 12px 14px; flex-direction: row; gap: 10px; }
.img-upload__dropzone--mini .img-upload__dz-icon { width: 20px; height: 20px; }
.img-upload__dropzone--mini .img-upload__dz-text { font-size: 0.82rem; }
.img-upload__dropzone--mini .img-upload__dz-hint { display: none; }

/* ===== پیش‌نمایش‌ها ===== */
.img-upload__previews {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}
.img-upload__previews[hidden] { display: none; }

/* حالت تک‌عکس: یک کارت بزرگ‌تر و محدود */
.img-upload__previews--single { grid-template-columns: minmax(0, 300px); }

.img-upload__card {
    position: relative;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 7px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
    transition: box-shadow .15s ease, border-color .15s ease;
}
.img-upload__card:hover { border-color: #c7d2fe; box-shadow: 0 3px 10px rgba(99, 102, 241, 0.14); }

.img-upload__thumb {
    display: block;
    width: 100%;
    height: 110px;
    object-fit: cover;
    border-radius: 8px;
    background: #f1f5f9;
}
.img-upload__previews--single .img-upload__thumb { height: 170px; }
.img-upload__previews--compact .img-upload__thumb { height: 72px; }

/* دکمهٔ حذف — روی گوشهٔ عکس، قرمز و کاملاً مشخص */
.img-upload__remove {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #dc2626;
    color: #fff;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.45);
    transition: background .15s ease, transform .15s ease;
    z-index: 2;
}
.img-upload__remove:hover { background: #b91c1c; transform: scale(1.08); }
.img-upload__remove:focus-visible { outline: 2px solid #dc2626; outline-offset: 2px; }
.img-upload__remove svg { width: 13px; height: 13px; }

/* نام و حجم فایل زیر عکس */
.img-upload__meta {
    margin-top: 6px;
    font-size: 0.7rem;
    color: #64748b;
    line-height: 1.7;
    direction: ltr;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.img-upload__meta--fa { direction: rtl; text-align: right; }

/* برچسب «تصویر فعلی» برای عکسِ ذخیره‌شده (حالت ویرایش) */
.img-upload__badge {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1;
    background: rgba(30, 41, 59, 0.82);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 999px;
    line-height: 1.6;
}

/* شمارندهٔ چندتایی */
.img-upload__count {
    grid-column: 1 / -1;
    font-size: 0.78rem;
    font-weight: 600;
    color: #047857;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 10px;
    padding: 7px 12px;
    text-align: center;
    margin: 0;
}

/* خطای اعتبارسنجی (فیلد اجباری خالی) */
.img-upload__error {
    display: none;
    margin-top: 6px;
    font-size: 0.78rem;
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 7px 12px;
}
.img-upload__error.is-visible { display: block; }

/* هم‌اندازه‌سازی کارت عکس‌های «فعلی» محصول با الگوی جدید
   (products/form.html — حذف/انتخاب تصویر اصلی) */
.image-card {
    position: relative;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 7px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}
.image-card img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 6px;
    background: #f1f5f9;
}
.image-card__delete {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #dc2626;
    color: #fff;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    font-size: 12px;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(220, 38, 38, 0.45);
    transition: background .15s ease, transform .15s ease;
    z-index: 2;
}
.image-card__delete:hover { background: #b91c1c; transform: scale(1.08); }
.image-card__delete svg { width: 13px; height: 13px; }

/* موبایل */
@media (max-width: 480px) {
    .img-upload__previews { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
    .img-upload__thumb { height: 92px; }
    .img-upload__previews--single .img-upload__thumb { height: 140px; }
    .img-upload__dropzone { padding: 16px 12px; }
}
