/**
 * SPE Table — بهبود مینیمال جدول‌های ادمین (opt-in با کلاس .spe-table)
 * جستجو + مرتب‌سازی ستونی + تغییرسایز ستون + خودتنظیمی به اندازه محتوا.
 * @version 15.240.0
 */

/* نوار ابزار + جعبه جستجو */
.spe-table-tools { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 10px; }
.spe-table-tools .button { display: inline-flex; align-items: center; gap: 6px; }
.spe-table-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-inline-start: auto; }

/* دکمه آیکن-only + لینک/دکمه اکسل (سبز یکپارچه) */
.spe-table-ic-btn,
.spe-goals-ic-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; padding: 0;
    border: 1px solid var(--spe-border-strong, #c3c4c7);
    border-radius: 7px; background: var(--spe-surface, #fff);
    color: var(--spe-icon-btn-color, #5f6368);
    cursor: pointer; line-height: 1; text-decoration: none;
    font: inherit;
}
.spe-table-ic-btn:hover,
.spe-goals-ic-btn:hover {
    border-color: var(--spe-icon-btn-hover-color, #6366f1);
    color: var(--spe-icon-btn-hover-color, #6366f1);
    background: var(--spe-surface-2, #f6f7f7);
}
.spe-table-ic-btn svg,
.spe-goals-ic-btn svg { width: 16px; height: 16px; }

.spe-table-xls,
.spe-table-xls-btn,
.spe-ord-xls {
    display: inline-flex; align-items: center; gap: 6px;
    height: 32px; padding: 0 12px;
    border: 1px solid color-mix(in srgb, var(--spe-success, #16a34a) 55%, #fff);
    border-radius: 7px;
    background: color-mix(in srgb, var(--spe-success) 10%, var(--spe-surface));
    color: color-mix(in srgb, var(--spe-success) 35%, var(--spe-text));
    font: inherit; font-size: 12px; font-weight: 500;
    text-decoration: none; cursor: pointer;
    line-height: 1;
}
.spe-table-xls:hover,
.spe-table-xls-btn:hover,
.spe-ord-xls:hover {
    background: color-mix(in srgb, var(--spe-success) 18%, var(--spe-surface));
    color: color-mix(in srgb, var(--spe-success) 35%, var(--spe-text));
}
.spe-table-xls svg,
.spe-table-xls-btn svg,
.spe-ord-xls svg { width: 16px; height: 16px; flex: 0 0 16px; color: var(--spe-icon-success-color, var(--spe-success, #16a34a)); }

/* منوی نمایش/مخفی ستون‌ها */
.spe-cols-wrap { position: relative; flex: 0 0 auto; }
.spe-cols-menu {
    display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
    background: var(--spe-surface, #fff);
    border: 1px solid var(--spe-border-strong, #c3c4c7);
    border-radius: 8px; padding: 6px; min-width: 150px;
    box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.spe-cols-menu.open { display: block; }
.spe-cols-menu label {
    display: flex; align-items: center; gap: 7px;
    padding: 4px 7px; border-radius: 5px;
    font-size: 12px; cursor: pointer; white-space: nowrap;
}
.spe-cols-menu label:hover { background: var(--spe-surface-2, #f6f7f7); }

/* ستون مخفی‌شده */
table.spe-table col.spe-col-hidden,
table.spe-table th.spe-col-hidden,
table.spe-table td.spe-col-hidden {
    width: 0 !important; max-width: 0; padding: 0; border: none;
    overflow: hidden; visibility: collapse;
}

/* ستون چک‌باکس انتخاب */
.spe-table th.spe-sel-th, .spe-table td.spe-sel-td { text-align: center; padding-inline: 4px; }
.spe-table tr.spe-row-selected > td { background: var(--spe-accent-soft, #eef5fb); }

/* نوار عملیات گروهی */
.spe-table-bulk {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 8px 12px;
    margin: 0 0 12px;
    background: var(--spe-accent-soft, #eef5fb);
    border: 0.5px solid #b9d4ec;
    border-radius: 6px;
}
.spe-table-bulk .spe-bulk-count { font-size: 13px; font-weight: 600; color: var(--spe-accent-dark, #1d4e79); }
.spe-table-bulk .spe-bulk-acts { display: flex; gap: 8px; flex-wrap: wrap; }
.spe-table-bulk .button.spe-danger { color: #b32d2e; border-color: #d6a0a0; }
.spe-table-bulk .button.spe-danger:hover { background: #f7e3e3; border-color: #b32d2e; }
.spe-table-search { position: relative; display: inline-flex; align-items: center; }
.spe-table-search > svg {
    position: absolute;
    inset-inline-start: auto;
    inset-inline-end: 12px;
    width: 14px; height: 14px;
    color: #8a8f94;
    pointer-events: none;
}
.spe-table-search input[type="search"] {
    padding: 6px 12px;
    padding-inline-start: 12px;
    padding-inline-end: 42px;
    direction: rtl;
    text-align: start;
    line-height: 1.6;
    border: 1px solid #dcdcde;
    border-radius: 6px;
    min-width: 220px;
    font-size: 13px;
    background: #fff;
}
.spe-table-search input[type="search"]:focus {
    border-color: var(--spe-accent, #2271b1);
    outline: none;
    box-shadow: 0 0 0 1px var(--spe-accent, #2271b1);
}

/* پوشش اسکرول افقی (وقتی ستون‌ها پهن‌تر از جا می‌شوند) */
.spe-table-scroll { overflow-x: auto; }

/* در حالت فعال، چیدمان ثابت تا عرض ستون‌ها دقیق و قابل‌کنترل باشد.
   min-width:100% ⇒ همیشه پهنای ستون را پر می‌کند (بدون فاصله خالی)، اما اگر ستون‌ها
   پهن‌تر شدند می‌تواند بزرگ‌تر شود و پوشش اسکرول افقی فعال می‌شود. */
table.spe-table.spe-table--on { table-layout: fixed; width: auto; min-width: 100%; max-width: none; }
table.spe-table.spe-table--on th,
table.spe-table.spe-table--on td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* عنوان کلیک‌پذیر برای مرتب‌سازی + فلش خنثی */
table.spe-table th { position: relative; }
table.spe-table th.spe-sortable { cursor: pointer; user-select: none; }
table.spe-table th .spe-sort-ind { margin-inline-start: 5px; font-size: 11px; opacity: .3; }
table.spe-table th[aria-sort] .spe-sort-ind { opacity: .85; }

/* دستگیره تغییرسایز ستون روی لبه inline-start هر ستون */
table.spe-table th .spe-col-resizer {
    position: absolute;
    inset-block: 0;
    inset-inline-start: -1px;
    width: 9px;
    cursor: col-resize;
    touch-action: none;
    z-index: 3;
}
table.spe-table th .spe-col-resizer::before {
    content: "";
    position: absolute;
    inset-block: 7px;
    inset-inline-start: 4px;
    width: 1px;
    background: transparent;
    transition: background .12s ease;
}
table.spe-table th:hover .spe-col-resizer::before,
table.spe-table.spe-col-dragging .spe-col-resizer::before { background: #c3c4c7; }
table.spe-table.spe-col-dragging { user-select: none; }

/* ردیف پنهان‌شده توسط جستجو + پیام خالی */
table.spe-table tr.spe-row-hidden { display: none; }
.spe-table-empty { color: #8a8f94; padding: 10px 4px; margin: 0; }
