/**
 * place-gallery.css
 *
 * استایل گالری تصاویر مطب/درمانگاه:
 *   - grid مدیریت تصاویر در فرم ویرایش (پنل پزشک و مدیر درمانگاه)
 *   - modal کراپ تصویر
 *   - گالری نمایش عمومی + lightbox در صفحه پروفایل
 *
 * مطابق style-guide: از CSS variables برند استفاده شده و dark-mode با @media
 * (prefers-color-scheme) پشتیبانی می‌شود (متغیرها در main-layout.css تعریف شده‌اند؛
 * اینجا fallback هم داریم تا مستقل هم درست رندر شود).
 *
 * تاریخ: 2026-07-03
 */

.gallery-help-text {
    font-size: 13px;
    color: var(--text-muted, #717171);
    line-height: 1.9;
    margin: 0 0 16px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.gallery-help-text i {
    color: var(--primary-color, rgb(37, 60, 137));
    margin-top: 3px;
    flex-shrink: 0;
}

.gallery-counter {
    display: inline-block;
    margin-inline-start: 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color, rgb(37, 60, 137));
    background: var(--primary-light, rgb(229, 233, 244));
    padding: 3px 10px;
    border-radius: var(--radius-full, 9999px);
    vertical-align: middle;
}

.gallery-empty-hint {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px;
    background: var(--bg-disabled, rgb(249, 250, 251));
    border: 1px dashed var(--border-default, #B0B0B0);
    border-radius: var(--radius-md, 8px);
    color: var(--text-muted, #717171);
    font-size: 14px;
}
.gallery-empty-hint i { color: var(--primary-color, rgb(37, 60, 137)); }

/* ===== Grid مدیریت ===== */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
}

.gallery-item {
    position: relative;
    aspect-ratio: 4 / 3;
    border-radius: var(--radius-md, 8px);
    overflow: hidden;
    background: var(--bg-disabled, #f2f2f2);
    border: 2px solid transparent;
    box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.08));
    /* transform را transition نمی‌کنیم چون هنگام reorder، جابجاییِ گرید باید آنی باشد؛
       فقط ظاهر (سایه/بوردر/شفافیت) نرم transition می‌شود. */
    transition: box-shadow 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.gallery-item:hover {
    box-shadow: var(--shadow-md, 0 4px 6px rgba(0, 0, 0, 0.1));
}
.gallery-item.dragging {
    opacity: 0.45;
    border-color: var(--primary-color, rgb(37, 60, 137));
    box-shadow: var(--shadow-lg, 0 10px 15px rgba(0, 0, 0, 0.15));
    /* در حین درگ، افکت hover همسایه‌ها نباید بپرد */
    z-index: 5;
}

.gallery-item-img {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
}

/* بَج وضعیت */
.gallery-status-badge {
    position: absolute;
    top: 8px;
    inset-inline-start: 8px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    padding: 3px 8px;
    border-radius: var(--radius-sm, 4px);
    z-index: 2;
    backdrop-filter: blur(2px);
}
.status-pending  .gallery-status-badge { background: var(--warning, #FFB400); color: #3a2c00; }
.status-approved .gallery-status-badge { background: var(--success, #00A699); }
.status-rejected .gallery-status-badge { background: var(--error, #DC2626); }

.status-rejected .gallery-item-img { filter: grayscale(0.6) opacity(0.7); }

/* دلیل رد */
.gallery-reject-reason {
    position: absolute;
    bottom: 0;
    inset-inline: 0;
    background: rgba(220, 38, 38, 0.92);
    color: #fff;
    font-size: 11px;
    padding: 6px 8px;
    line-height: 1.5;
    z-index: 2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* دکمه حذف */
.gallery-delete-btn {
    position: absolute;
    top: 8px;
    inset-inline-end: 8px;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full, 9999px);
    border: none;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease;
    z-index: 3;
}
.gallery-item:hover .gallery-delete-btn { opacity: 1; }
.gallery-delete-btn:hover { background: var(--error, #DC2626); }

/* دستگیره جابجایی — نقطهٔ شروع درگ (HTML5 DnD دسکتاپ + touch موبایل).
   touch-action:none تا کشیدنِ لمسی روی دستگیره باعث اسکرول صفحه نشود. */
.gallery-drag-handle {
    position: absolute;
    bottom: 8px;
    inset-inline-end: 8px;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm, 4px);
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    opacity: 0;
    cursor: grab;
    touch-action: none;
    transition: opacity 0.15s ease, background 0.15s ease;
    z-index: 4;
}
.gallery-drag-handle:active { cursor: grabbing; background: var(--primary-color, rgb(37, 60, 137)); }
.gallery-item:hover .gallery-drag-handle { opacity: 1; }
/* روی دستگاه‌های لمسی (بدون hover) دستگیره همیشه دیده شود تا قابل استفاده باشد */
@media (hover: none) {
    .gallery-drag-handle { opacity: 0.9; }
}

/* نشانگرِ محلِ درج حین کشیدن (بدون جابجایی واقعیِ تایل‌ها تا لرزش نشود).
   یک خط عمودیِ برند در لبهٔ تایلی که drop قبل/بعد از آن می‌افتد. */
.gallery-item.drop-before::before,
.gallery-item.drop-after::after {
    content: '';
    position: absolute;
    top: 6%;
    height: 88%;
    width: 4px;
    border-radius: 2px;
    background: var(--primary-color, rgb(37, 60, 137));
    z-index: 6;
}
/* RTL: «قبل از این تایل» یعنی سمت راستِ آن. نشانگر داخل لبه (چون تایل overflow:hidden دارد). */
.gallery-item.drop-before::before { right: 3px; }
.gallery-item.drop-after::after { left: 3px; }

/* دکمه افزودن */
.gallery-add-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    aspect-ratio: 4 / 3;
    border: 2px dashed var(--border-default, #B0B0B0);
    border-radius: var(--radius-md, 8px);
    color: var(--text-muted, #717171);
    background: var(--bg-disabled, rgb(249, 250, 251));
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
    font-size: 13px;
    font-weight: 600;
}
.gallery-add-btn:hover {
    border-color: var(--primary-color, rgb(37, 60, 137));
    color: var(--primary-color, rgb(37, 60, 137));
    background: var(--primary-light, rgb(229, 233, 244));
}
.gallery-add-btn i { font-size: 22px; }

.gallery-max-reached {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 14px;
    background: rgba(0, 166, 153, 0.1);
    color: var(--success, #00A699);
    border-radius: var(--radius-md, 8px);
    font-size: 13px;
    font-weight: 600;
}

/* ===== Modal کراپ ===== */
.gallery-crop-modal {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.gallery-crop-backdrop {
    position: absolute;
    inset: 0;
    background: var(--bg-overlay, rgba(0, 0, 0, 0.6));
    backdrop-filter: blur(2px);
}
.gallery-crop-box {
    position: relative;
    width: 100%;
    max-width: 640px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-component, #fff);
    border-radius: var(--radius-lg, 12px);
    box-shadow: var(--shadow-2xl, 0 25px 50px rgba(0, 0, 0, 0.25));
    overflow: hidden;
}
.gallery-crop-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-light, #DDDDDD);
}
.gallery-crop-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #000);
    display: flex;
    align-items: center;
    gap: 8px;
}
.gallery-crop-header h3 i { color: var(--primary-color, rgb(37, 60, 137)); }
.gallery-crop-queue {
    display: inline-block;
    margin-inline-start: 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color, rgb(37, 60, 137));
    background: var(--primary-light, rgb(229, 233, 244));
    padding: 2px 10px;
    border-radius: var(--radius-full, 9999px);
    vertical-align: middle;
}
.gallery-crop-close {
    border: none;
    background: none;
    font-size: 26px;
    line-height: 1;
    color: var(--text-muted, #717171);
    cursor: pointer;
    padding: 0 4px;
}
.gallery-crop-close:hover { color: var(--error, #DC2626); }

.gallery-crop-body {
    padding: 16px;
    background: var(--bg-primary, rgb(239, 241, 243));
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.gallery-crop-canvas-wrapper {
    max-height: 52vh;
    margin: 0 auto;
}
.gallery-crop-canvas-wrapper img {
    max-width: 100%;
    display: block;
}

.gallery-crop-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-light, #DDDDDD);
    justify-content: center;
}
.gallery-crop-toolbar-group {
    display: flex;
    gap: 4px;
    padding-inline-end: 8px;
    border-inline-end: 1px solid var(--border-light, #DDDDDD);
}
.gallery-crop-toolbar-group:last-child { border-inline-end: none; padding-inline-end: 0; }
.gallery-crop-btn {
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border-light, #DDDDDD);
    border-radius: var(--radius-sm, 4px);
    background: var(--bg-component, #fff);
    color: var(--text-secondary, #222);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.15s ease;
}
.gallery-crop-btn:hover {
    border-color: var(--primary-color, rgb(37, 60, 137));
    color: var(--primary-color, rgb(37, 60, 137));
}
.gallery-crop-btn.active {
    background: var(--primary-color, rgb(37, 60, 137));
    border-color: var(--primary-color, rgb(37, 60, 137));
    color: #fff;
}

.gallery-crop-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 14px 18px;
    border-top: 1px solid var(--border-light, #DDDDDD);
}
.gallery-btn-cancel, .gallery-btn-confirm {
    padding: 10px 20px;
    border-radius: var(--radius-md, 8px);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}
.gallery-btn-cancel {
    background: var(--bg-component, #fff);
    border-color: var(--border-default, #B0B0B0);
    color: var(--text-secondary, #222);
}
.gallery-btn-cancel:hover { background: var(--bg-hover, #F7F7F7); }
.gallery-btn-confirm {
    background: var(--primary-color, rgb(37, 60, 137));
    color: #fff;
}
.gallery-btn-confirm:hover { background: var(--primary-hover, rgb(30, 48, 110)); }
.gallery-btn-confirm:disabled { opacity: 0.6; cursor: not-allowed; }

/* ===== Toast =====
   موقعیت فیزیکی صریح (left، نه inset-inline): در RTL، inset-inline-start=right و همراه با
   translateX(-50%) توست را از صفحه بیرون می‌انداخت (به‌ویژه موبایل). با left:50% وسط‌چین
   قابل‌اعتماد در هر جهتی است. box-sizing + max-width تضمین می‌کند از لبه بیرون نزند. */
.gallery-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translate(-50%, 20px);
    box-sizing: border-box;
    background: var(--text-primary, #000);
    color: #fff;
    padding: 12px 22px;
    border-radius: var(--radius-md, 8px);
    font-size: 14px;
    line-height: 1.6;
    text-align: center;
    z-index: 100001;
    box-shadow: var(--shadow-lg, 0 10px 15px rgba(0, 0, 0, 0.15));
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    width: max-content;
    max-width: calc(100vw - 32px);
}
.gallery-toast.show { opacity: 1; transform: translate(-50%, 0); }
.gallery-toast-error { background: var(--error, #DC2626); }

/* ===== نمایش عمومی در پروفایل ===== */
.place-public-gallery {
    margin-top: 14px;
}
.place-public-gallery-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted, #717171);
    margin: 0 0 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.place-gallery-thumbs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.place-gallery-thumb {
    width: 84px;
    height: 63px;
    border-radius: var(--radius-md, 8px);
    background-size: cover;
    background-position: center;
    cursor: pointer;
    border: 1px solid var(--border-light, #DDDDDD);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    flex-shrink: 0;
}
.place-gallery-thumb:hover {
    transform: scale(1.04);
    box-shadow: var(--shadow-md, 0 4px 6px rgba(0, 0, 0, 0.1));
}
.place-gallery-thumb.more-thumb {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
}
.place-gallery-thumb.more-thumb::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    border-radius: var(--radius-md, 8px);
}
.place-gallery-thumb.more-thumb span { position: relative; z-index: 1; }

/* ===== Lightbox عمومی ===== */
.pg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.9);
}
.pg-lightbox.open { display: flex; }
.pg-lightbox-img {
    max-width: 92vw;
    max-height: 86vh;
    border-radius: var(--radius-md, 8px);
    box-shadow: var(--shadow-2xl, 0 25px 50px rgba(0, 0, 0, 0.5));
    object-fit: contain;
}
.pg-lightbox-close,
.pg-lightbox-nav {
    position: absolute;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full, 9999px);
    transition: background 0.15s ease;
}
.pg-lightbox-close {
    top: 20px;
    inset-inline-end: 20px;
    width: 44px;
    height: 44px;
    font-size: 22px;
}
.pg-lightbox-nav {
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    font-size: 20px;
}
/* RTL: موقعیت فیزیکی صریح. «بعدی» (فلش چپ ‹) سمت چپ، «قبلی» (فلش راست ›) سمت راست —
   مطابق جهت خواندنِ راست‌به‌چپِ گالری (اولین عکس سمت راست، بعدی‌ها به‌سمت چپ). */
.pg-lightbox-next { left: 20px; }
.pg-lightbox-prev { right: 20px; }
.pg-lightbox-close:hover,
.pg-lightbox-nav:hover { background: rgba(255, 255, 255, 0.3); }
.pg-lightbox-counter {
    position: absolute;
    bottom: 22px;
    inset-inline-start: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 14px;
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 14px;
    border-radius: var(--radius-full, 9999px);
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
    .gallery-crop-toolbar { gap: 6px; }
    .gallery-crop-toolbar-group { padding-inline-end: 6px; }
    .gallery-crop-btn { min-width: 34px; height: 34px; font-size: 13px; }
    .place-gallery-thumb { width: 72px; height: 54px; }
    .pg-lightbox-nav { width: 42px; height: 42px; }
}

/* ===== Dark mode (در صورت نبود متغیرها در main-layout) ===== */
@media (prefers-color-scheme: dark) {
    .gallery-item,
    .gallery-add-btn { background: #2d2d2d; }
    .gallery-add-btn { border-color: #404040; }
    .gallery-empty-hint { background: #2d2d2d; border-color: #404040; }
}
