:root {
    --bg: #0f172a;
    --card: #111827;
    --muted: #6b7280;
    --fg: #e5e7eb;
    --acc: #22d3ee;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --border: #374151;
    --hover: #1f2937;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg), #020617);
    color: var(--fg);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px;
}

.card {
    background: rgba(17, 24, 39, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    margin-bottom: 30px;
}

h1 {
    color: #fff;
    margin-bottom: 15px;
    font-size: 32px;
    font-weight: 700;
    text-align: center;
}

h1 i {
    color: var(--acc);
    margin-left: 10px;
}

.lead {
    color: #cbd5e1;
    text-align: center;
    font-size: 18px;
    margin-bottom: 40px;
    opacity: 0.9;
}

.step-section {
    margin: 40px 0;
    padding: 30px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.step-section h3 {
    color: var(--acc);
    margin-bottom: 20px;
    font-size: 22px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* رفع الملفات */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: 15px;
    padding: 60px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.02);
}

.upload-area:hover {
    border-color: var(--acc);
    background: rgba(34, 211, 238, 0.05);
}

.upload-area.dragover {
    border-color: var(--acc);
    background: rgba(34, 211, 238, 0.1);
    transform: scale(1.02);
}

.upload-content {
    pointer-events: none;
}

.upload-icon {
    font-size: 48px;
    color: var(--acc);
    margin-bottom: 15px;
}

.upload-area p {
    font-size: 18px;
    margin-bottom: 10px;
}

.upload-area .small {
    color: var(--muted);
    font-size: 14px;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    padding: 15px;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 10px;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.file-info i {
    color: var(--success);
    font-size: 20px;
}

/* النماذج */
.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .row {
        grid-template-columns: 1fr;
    }
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    color: #cbd5e1;
    font-weight: 500;
    margin-bottom: 8px;
}

select, input[type="file"] {
    width: 100%;
    padding: 12px 15px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(11, 18, 32, 0.8);
    color: var(--fg);
    font-size: 16px;
    transition: all 0.3s ease;
}

select:focus {
    outline: none;
    border-color: var(--acc);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}

.checkbox-group {
    display: flex;
    align-items: center;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
    margin: 0;
}

/* الأزرار */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #06b6d4, var(--acc));
    color: #001018;
    border: none;
    padding: 15px 25px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    justify-content: center;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(34, 211, 238, 0.3);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* الإحصائيات */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-item i {
    font-size: 24px;
    color: var(--acc);
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #fff;
}

.stat-label {
    font-size: 14px;
    color: var(--muted);
}

/* عرض الملخّص */
#summary-display {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 15px;
    padding: 30px;
    margin: 30px 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    line-height: 1.8;
}

#summary-display h2 {
    color: var(--acc);
    margin: 25px 0 15px 0;
    font-size: 20px;
}

#summary-display h3 {
    color: #cbd5e1;
    margin: 20px 0 10px 0;
    font-size: 18px;
}

#summary-display ul, #summary-display ol {
    margin: 15px 0;
    padding-right: 20px;
}

#summary-display li {
    margin-bottom: 8px;
}

#summary-display p {
    margin-bottom: 15px;
}

#summary-display .highlight {
    background: rgba(34, 211, 238, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--acc);
}

/* قسم حفظ التعديلات في السجل */
.save-edits-section {
    margin-top: 30px;
    padding: 18px 20px;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.08), rgba(59, 130, 246, 0.08));
    border: 1px dashed rgba(34, 197, 94, 0.4);
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.save-edits-btn {
    background: linear-gradient(135deg, #16a34a, #059669);
    font-size: 14px;
    padding: 10px 22px;
}

.save-edits-btn.is-loading {
    opacity: 0.75;
    cursor: progress;
}

.save-edits-status {
    font-size: 14px;
    color: #cbd5e1;
}

.save-edits-status.pending { color: #93c5fd; }
.save-edits-status.success { color: #4ade80; }
.save-edits-status.error   { color: #f87171; }

/* أزرار التصدير */
.export-section {
    margin-top: 40px;
    padding-top: 30px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.export-section h4 {
    color: #cbd5e1;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.export-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.export-btn {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    font-size: 14px;
    padding: 12px 20px;
}

.export-btn.whatsapp {
    background: linear-gradient(135deg, #25d366, #128c7e);
}

/* حالة التحميل */
.loading {
    text-align: center;
    padding: 60px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(34, 211, 238, 0.3);
    border-top: 4px solid var(--acc);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* التنبيهات */
.alert {
    padding: 15px 20px;
    border-radius: 10px;
    margin: 20px 0;
    font-weight: 500;
}

.alert.success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success);
}

.alert.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--error);
}

.alert.warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: var(--warning);
}

/* الشارات */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 50px;
    background: var(--acc);
    color: #001018;
    font-weight: 700;
    font-size: 12px;
    margin-right: 10px;
}

/* قسم المعلومات */
.info-section {
    background: rgba(17, 24, 39, 0.6);
    border-radius: 20px;
    padding: 40px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.info-section h4 {
    color: var(--acc);
    margin-bottom: 25px;
    font-size: 22px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
}

.info-item {
    display: flex;
    gap: 15px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.info-item i {
    font-size: 24px;
    color: var(--acc);
    margin-top: 5px;
}

.info-item h5 {
    color: #fff;
    margin-bottom: 8px;
    font-size: 16px;
}

.info-item p {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

/* استجابة للأجهزة المحمولة */
@media (max-width: 768px) {
    .container {
        margin: 10px;
        padding: 15px;
    }
    
    .card {
        padding: 25px;
    }
    
    h1 {
        font-size: 24px;
    }
    
    .lead {
        font-size: 16px;
    }
    
    .upload-area {
        padding: 40px 15px;
    }
    
    .upload-icon {
        font-size: 36px;
    }
    
    .info-grid {
        grid-template-columns: 1fr;
    }
    
    .export-buttons {
        grid-template-columns: 1fr 1fr;
    }
}

/* تحسينات RTL */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .upload-area,
[dir="rtl"] .step-section h3,
[dir="rtl"] .info-section h4,
[dir="rtl"] .export-section h4 {
    text-align: right;
}

[dir="rtl"] h1 i {
    margin-right: 10px;
    margin-left: 0;
}

[dir="rtl"] .step-section h3 i,
[dir="rtl"] .info-section h4 i,
[dir="rtl"] .export-section h4 i {
    margin-left: 10px;
    margin-right: 0;
}

[dir="rtl"] ul, [dir="rtl"] ol {
    padding-left: 20px;
    padding-right: 0;
}

/* قسم المراجع القانونية */
.legal-references-section {
    margin-top: 30px;
    padding: 25px;
    background: rgba(245, 158, 11, 0.05);
    border-radius: 15px;
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.legal-references-section h4 {
    color: #f59e0b;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
}

.small-text {
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 20px;
}

/* تبويبات المراجع */
.references-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--fg);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.tab-btn.active {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #001018;
    border-color: #f59e0b;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* منطقة رفع المراجع */
.references-upload-area {
    border: 2px dashed #f59e0b;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(245, 158, 11, 0.02);
    margin-bottom: 15px;
}

.references-upload-area:hover {
    border-color: #d97706;
    background: rgba(245, 158, 11, 0.05);
}

.references-upload-area.dragover {
    border-color: #d97706;
    background: rgba(245, 158, 11, 0.1);
    transform: scale(1.01);
}

/* قائمة المراجع المرفوعة */
.references-list {
    max-height: 200px;
    overflow-y: auto;
}

.reference-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.reference-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.reference-info i {
    color: #f59e0b;
    font-size: 16px;
}

.reference-name {
    font-weight: 500;
}

.reference-size {
    font-size: 12px;
    color: var(--muted);
}

.remove-reference {
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.remove-reference:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* الكتابة اليدوية */
.manual-references {
    width: 100%;
}

.manual-references label {
    display: block;
    margin-bottom: 10px;
    color: #cbd5e1;
    font-weight: 500;
}

#manual-references-text {
    width: 100%;
    min-height: 150px;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(11, 18, 32, 0.8);
    color: var(--fg);
    font-size: 14px;
    line-height: 1.6;
    resize: vertical;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#manual-references-text:focus {
    outline: none;
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

#manual-references-text::placeholder {
    color: var(--muted);
    opacity: 0.7;
}

/* تحسينات للأجهزة المحمولة */
@media (max-width: 768px) {
    .references-tabs {
        flex-direction: column;
    }
    
    .tab-btn {
        justify-content: center;
    }
    
    .references-upload-area {
        padding: 30px 15px;
    }
    
    .reference-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
}

/* ========================================================================== */
/* تعديل تفاصيل الواقعة بالنقر (inline-edit)                                  */
/* ========================================================================== */

.edit-hint {
    color: #94a3b8;
    font-size: 0.88em;
    margin: 0 0 16px 0;
    line-height: 1.5;
}

.edit-hint i {
    color: #6366f1;
    margin-left: 4px;
}

.editable-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    position: relative;
    max-width: 100%;
    vertical-align: middle;
}

.editable-field {
    display: inline-block;
    min-width: 120px;
    padding: 2px 8px;
    border-radius: 5px;
    border: 1px dashed transparent;
    cursor: text;
    transition: background 0.18s ease, border-color 0.18s ease;
    outline: none;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
}

.editable-field.multiline {
    display: block;
    min-height: 1.6em;
    width: 100%;
}

.editable-wrapper:hover .editable-field {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.45);
}

.editable-field:focus {
    background: rgba(99, 102, 241, 0.18);
    border-color: rgba(99, 102, 241, 0.85);
    border-style: solid;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.editable-field:empty::before {
    content: attr(data-placeholder);
    color: #94a3b8;
    font-style: italic;
}

.edit-pencil {
    color: #94a3b8;
    font-size: 0.78em;
    opacity: 0;
    transition: opacity 0.18s ease, color 0.18s ease;
    pointer-events: none;
}

.editable-wrapper:hover .edit-pencil,
.editable-field:focus + .edit-pencil {
    opacity: 0.85;
    color: #6366f1;
}

.edit-confirm {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px;
    padding: 3px 10px;
    background: rgba(34, 197, 94, 0.18);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.4);
    border-radius: 999px;
    font-size: 0.82em;
    font-weight: 600;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
}

.edit-confirm.show {
    opacity: 1;
    transform: translateY(0);
}

.edit-confirm i {
    font-size: 0.95em;
}

/* ========================================================================== */
/* تحرير القوائم وأزرار الإضافة/الحذف وتنسيقات إضافية لجميع الأقسام             */
/* ========================================================================== */

/* قسم التقييم القانوني المحايد */
.neutral-assessment {
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.35);
    border-right: 4px solid #6366f1;
    padding: 18px 20px;
    border-radius: 12px;
    margin: 0 0 22px 0;
}

.neutral-assessment .neutral-disclaimer {
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: #fbbf24;
    padding: 10px 14px;
    border-radius: 8px;
    margin: 0 0 14px 0;
    font-size: 0.92rem;
    line-height: 1.6;
}

.neutral-assessment h3 {
    color: #a5b4fc;
    margin: 14px 0 6px 0;
    font-size: 1rem;
}

/* تلميح عام في أعلى الملخّص */
.global-edit-hint {
    background: rgba(99, 102, 241, 0.08);
    border: 1px dashed rgba(99, 102, 241, 0.35);
    padding: 10px 14px;
    border-radius: 10px;
    margin: 0 0 18px 0;
}

/* الحقول متعددة الأسطر تحتاج إلى wrapper بمستوى block ليأخذ كامل العرض */
.editable-wrapper.editable-block {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
    margin: 6px 0;
}

.editable-wrapper.editable-block .editable-field {
    flex: 1;
    min-width: 0;
}

/* قوائم قابلة للتحرير: نمنح المسافة لزر الحذف ونرتّب العناصر بشكل واضح */
.editable-list {
    padding-inline-start: 1.4em;
}

.editable-list li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
    line-height: 1.7;
}

.editable-list li > .editable-wrapper {
    flex: 1;
    min-width: 0;
}

/* رقم صفحة الاقتباس بحجم أصغر ولون فاتح */
.quote-page {
    color: #94a3b8;
    font-size: 0.9em;
    white-space: nowrap;
}

/* زر إضافة عنصر إلى قائمة (موضوع داخل عنوان <h2>) */
.list-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 12px;
    padding: 4px 12px;
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.4);
    border-radius: 999px;
    font-size: 0.65em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s ease, transform 0.12s ease;
    vertical-align: middle;
}

.list-add-btn:hover {
    background: rgba(34, 197, 94, 0.28);
    transform: translateY(-1px);
}

.list-add-btn:active {
    transform: translateY(0);
}

/* زر حذف عنصر من قائمة */
.list-remove-btn {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    padding: 0;
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.35);
    border-radius: 50%;
    font-size: 0.85em;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.list-remove-btn:hover {
    background: rgba(239, 68, 68, 0.28);
    color: #fff;
    transform: scale(1.05);
}

.list-remove-btn:active {
    transform: scale(0.95);
}

.empty-list-hint {
    color: #94a3b8;
    font-style: italic;
    margin: 6px 0 16px 0;
}

/* صندوق نسخة الواتساب القابل للتحرير — يحافظ على الستايل الأخضر السابق */
.whatsapp-edit-block {
    margin-top: 10px;
}

.editable-field.whatsapp-edit {
    background: rgba(37, 211, 102, 0.1);
    border: 1px solid rgba(37, 211, 102, 0.3);
    padding: 15px;
    border-radius: 10px;
    font-family: 'Courier New', monospace;
    line-height: 1.7;
    min-height: 6em;
}

.editable-wrapper.editable-block:has(.whatsapp-edit):hover .editable-field.whatsapp-edit {
    background: rgba(37, 211, 102, 0.18);
    border-color: rgba(37, 211, 102, 0.55);
}
