/* ============================================================================
   مركز الدعم داخل بوابة التاجر (/portal/support) — مرآة app/styles/support.css
   بتوكنز البوابة (portal.css): --surface/--text/--border/--primary حصراً.
   القواعد المنطقية (inline-start/end) كي تنقلب تلقائياً مع تبديل اللغة.
   ============================================================================ */

/* جسم الصفحة */
.sp-body {
    padding: 22px clamp(14px, 3vw, 30px) 48px;
    max-width: 1060px;
    margin-inline: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* داخل التبويب المدمج (#tab-support في /portal): ‎.content في portal.html
   يوفّر العرض والحشو أصلاً — نحيّل حشو الجسم المستقل وعرضه الأقصى. */
.sp-body.sp-embed {
    padding: 0;
    max-width: none;
}

/* شريط زر «بطاقة جديدة» */
.sp-toolbar {
    display: flex;
    justify-content: flex-end;
}

.sp-top-action {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
    background: var(--primary-soft);
    color: var(--primary);
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 12.5px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.sp-top-action:hover {
    background: color-mix(in srgb, var(--primary) 14%, transparent);
    box-shadow: var(--shadow-sm);
}

/* ===== الرأس التعريفي ===== */
.sp-hero {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 20px 24px;
    border-radius: var(--radius);
    background:
        radial-gradient(420px 180px at 12% 0%, color-mix(in srgb, var(--primary) 14%, transparent), transparent 70%),
        var(--surface-2);
    border: 1px solid color-mix(in srgb, var(--primary) 16%, transparent);
}

.sp-hero-text {
    flex: 1 1 auto;
    min-width: 0;
}

.sp-hero-title {
    margin: 0 0 4px;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--primary-deep);
}

.sp-hero-sub {
    margin: 0;
    font-size: 12.5px;
    opacity: 0.78;
    max-width: 52ch;
}

.sp-hero-art {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    color: var(--primary);
    opacity: 0.55;
}

@media (max-width: 560px) {
    .sp-hero { padding: 16px; }
    .sp-hero-art { width: 40px; height: 40px; }
}

/* ===== عدّادات الحالة (عرض فقط — بلا فلترة) =====
   سطر مضغوط فوق الجدول مباشرة: نقطة بلون الحالة + التسمية + الرقم */
.sp-counts {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 18px;
    padding-block-end: 10px;
    margin-block-end: 10px;
}

.sp-count {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.sp-count-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: none;
}

/* ألوان النقاط مرآة ألوان رقائق الحالة (.sp-pill.st-*) في هذه اللوحة */
.sp-count-dot.dot-all { background: var(--primary); }
.sp-count-dot.dot-open { background: #a06a12; }
.sp-count-dot.dot-answered { background: #0d8873; }
.sp-count-dot.dot-closed { background: var(--slate); }

.sp-count-label {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--primary-deep);
}

/* فاصل «|» بين العدّادات */
.sp-count + .sp-count::before {
    content: '|';
    margin-inline-end: 18px;
    margin-inline-start: -11px; /* تعويض نصف فجوة العنصر ليتوسّط الفاصل */
    color: var(--border-main, var(--border));
    font-weight: 400;
}

.sp-stat-count {
    font-size: 13px;
    font-weight: 800;
    color: var(--text-title, var(--primary-deep));
    font-variant-numeric: tabular-nums;
}

/* ===== عناوين الأقسام ===== */
.sp-section-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding-block-end: 10px;
    border-block-end: 1px solid var(--border);
    margin-block-end: 12px;
}

.sp-section-title {
    margin: 0;
    font-size: 13.5px;
    font-weight: 800;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.sp-section-title svg {
    width: 15px;
    height: 15px;
    color: var(--primary);
}

.sp-section-hint {
    font-size: 11px;
    opacity: 0.6;
    font-variant-numeric: tabular-nums;
}

/* ===== الجدول ===== */
.sp-table-wrapper {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}

.sp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

.sp-table thead th {
    text-align: start;
    padding: 11px 14px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text);
    opacity: 0.85;
    background: color-mix(in srgb, var(--bg) 55%, var(--surface));
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
}

.sp-table tbody td {
    padding: 11px 14px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.sp-table tbody tr:last-child td {
    border-bottom: none;
}

.sp-table .sp-main {
    cursor: pointer;
    transition: background-color 0.12s ease;
}

.sp-table .sp-main:hover {
    background: color-mix(in srgb, var(--primary) 5%, transparent);
}

.sp-table .sp-td-id {
    font-weight: 700;
    color: var(--primary-deep);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.sp-table .sp-td-subject {
    font-weight: 600;
    color: var(--primary-deep);
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sp-table .sp-td-date {
    font-size: 11.5px;
    opacity: 0.75;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* رقائق الحالة — نظائر ألوان شارات البوابة (amber/mint/slate) */
.sp-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 700;
    border-radius: var(--radius-pill);
    white-space: nowrap;
}

.sp-pill::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.sp-pill.st-open {
    background: var(--amber-soft);
    color: #a06a12;
}

.sp-pill.st-answered {
    background: var(--green-soft);
    color: #0d8873;
}

.sp-pill.st-closed {
    background: var(--slate-soft);
    color: var(--slate);
}

/* ===== المودالات (بطاقة جديدة + تفاصيل) ===== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: color-mix(in srgb, #0f172a 55%, transparent);
    backdrop-filter: blur(2px);
}

.sp-modal-content {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-height: min(88vh, 780px);
    display: flex;
    flex-direction: column;
}

.sp-detail-modal {
    max-width: 760px;
}

/* مودال البطاقة الجديدة أضيق من مودال المحادثة */
#supportTicketModal .sp-modal-content {
    max-width: 560px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    margin: 0;
    font-size: 15px;
    font-weight: 800;
    color: var(--primary-deep);
}

.close-btn {
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 8px;
}

.close-btn:hover {
    background: var(--primary-soft);
    color: var(--primary);
}

.sp-modal-body {
    padding: 16px 20px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sp-modal-sub {
    margin: 0;
    font-size: 12px;
    opacity: 0.72;
}

.sp-modal-body form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sp-req {
    color: var(--red);
    font-weight: 800;
}

.sp-opt {
    font-size: 10.5px;
    opacity: 0.6;
    font-weight: 500;
}

/* ===== مودال التفاصيل: المحادثة + الردّ ===== */
.sp-detail-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 20px 20px;
    overflow-y: auto;
}

/* سطر التعريف: الرقم + رقائق الحالة/النوع/الأولوية + آخر تحديث */
.sp-detail-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary-deep);
    font-variant-numeric: tabular-nums;
}

.sp-meta-chip {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    background: var(--surface);
}

.sp-meta-when {
    margin-inline-start: auto;
    font-weight: 500;
    font-size: 11.5px;
    color: var(--text);
    opacity: 0.75;
}

.sp-msgs {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: min(46vh, 420px);
    overflow-y: auto;
    padding: 12px;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: var(--surface-2);
}

.sp-msg {
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 12.5px;
    max-width: 88%;
    overflow-wrap: anywhere;
}

.sp-msg-merchant {
    align-self: flex-start;
    background: var(--primary-soft);
    border-start-start-radius: 4px;
}

.sp-msg-admin {
    align-self: flex-end;
    background: var(--green-soft);
    border-start-end-radius: 4px;
}

.sp-msg-head {
    display: flex;
    gap: 8px;
    align-items: baseline;
    font-size: 11px;
    font-weight: 700;
    margin-block-end: 4px;
}

.sp-msg-when {
    font-weight: 500;
    opacity: 0.65;
}

.sp-msg-attachment {
    display: inline-block;
    margin-block-start: 6px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
}

.sp-msg-attachment img {
    display: block;
    max-width: 100%;
    max-height: 220px;
}

/* نموذج الرد داخل المودال */
.sp-reply {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid color-mix(in srgb, var(--primary) 18%, transparent);
    border-radius: 12px;
    padding: 10px;
    background: color-mix(in srgb, var(--primary-soft) 40%, var(--surface));
}

.sp-reply textarea {
    min-height: 64px;
    resize: vertical;
}

.sp-reply-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.sp-attach-label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px dashed color-mix(in srgb, var(--primary) 35%, transparent);
    border-radius: var(--radius-pill);
    padding: 8px 14px;
    min-height: 38px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sp-attach-label:hover {
    background: var(--primary-soft);
}

.sp-reply-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    padding: 9px 18px;
    min-height: 38px;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.sp-reply-btn:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-primary);
}

.sp-reply-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

/* حالة الفراغ */
.sp-empty {
    border: 1px dashed color-mix(in srgb, var(--primary) 25%, transparent);
    border-radius: 16px;
    padding: 40px 22px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: color-mix(in srgb, var(--bg) 40%, var(--surface));
}

.sp-empty svg {
    width: 38px;
    height: 38px;
    color: var(--primary);
    opacity: 0.5;
}

.sp-empty-text {
    font-size: 13px;
    opacity: 0.75;
    max-width: 42ch;
}

.sp-empty-cta {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    padding: 10px 18px;
    min-height: 42px;
    font-size: 12.5px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.sp-empty-cta:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-primary);
}

/* ===== الأسئلة الشائعة ===== */
.sp-faq-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
    gap: 12px;
}

.sp-faq-item {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.sp-faq-item:hover {
    border-color: color-mix(in srgb, var(--primary) 32%, transparent);
    box-shadow: var(--shadow);
}

.sp-faq-q {
    font-size: 12.5px;
    font-weight: 800;
    line-height: 1.5;
    color: var(--primary-deep);
    display: flex;
    gap: 8px;
    align-items: baseline;
}

.sp-faq-q::before {
    content: '؟';
    flex: 0 0 auto;
    order: 2; /* في RTL تظهر في الطرف الأيسر كعلامة قيادية */
    width: 20px;
    height: 20px;
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--primary) 10%, var(--surface));
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transform: translateY(3px);
}

html[dir='ltr'] .sp-faq-q::before {
    order: 0;
}

.sp-faq-a {
    font-size: 12px;
    line-height: 1.7;
    color: var(--text);
    opacity: 0.82;
    white-space: pre-line;
}

/* احترام تقليل الحركة */
@media (prefers-reduced-motion: reduce) {
    .sp-faq-item,
    .sp-table .sp-main,
    .sp-top-action,
    .sp-empty-cta,
    .sp-reply-btn {
        transition: none !important;
        animation: none !important;
    }
}
