* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #1e3a8a;
    --secondary-color: #3b82f6;
    --accent-color: #f59e0b;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --text-color: #1f2937;
    --text-light: #6b7280;
    --border-color: #e5e7eb;
    --bg-light: #f9fafb;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f3f4f6;
    color: var(--text-color);
    line-height: 1.6;
    direction: rtl;
    text-align: right;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* الرأس */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 40px 20px;
    border-radius: 10px;
    margin-bottom: 30px;
    box-shadow: var(--shadow-lg);
    text-align: right;
}

.header-content h1 {
    font-size: 32px;
    margin-bottom: 10px;
    font-weight: 700;
}

.header-content p {
    font-size: 16px;
    opacity: 0.9;
}

/* القائمة العلوية */
.nav-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    flex-wrap: wrap;
    flex-direction: row-reverse;
}

.nav-btn {
    flex: 1;
    min-width: 180px;
    padding: 12px 20px;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
    transition: all 0.3s ease;
}

.nav-btn:hover {
    border-color: var(--secondary-color);
    color: var(--secondary-color);
}

.nav-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* التبويبات */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* الأقسام */
.section {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.section h2 {
    font-size: 24px;
    margin-bottom: 20px;
    color: var(--primary-color);
    border-bottom: 3px solid var(--accent-color);
    padding-bottom: 10px;
}

.section h3 {
    font-size: 18px;
    margin-top: 25px;
    margin-bottom: 15px;
    color: var(--primary-color);
}

/* شبكة الإحصائيات */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 25px;
    border-radius: 10px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 10px;
}

.stat-label {
    font-size: 14px;
    opacity: 0.9;
}

/* النماذج */
.form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.form-group label {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    direction: rtl;
    text-align: right;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* حقول مقروءة فقط (ثابتة) */
.form-group input[readonly] {
    background-color: #f5f5f5;
    color: #555;
    cursor: not-allowed;
    font-weight: 600;
    border-color: #ccc;
}

.form-section {
    border: 1px solid var(--border-color);
    padding: 20px;
    border-radius: 8px;
    background: var(--bg-light);
}

.form-section h3 {
    margin-top: 0;
}

.form-actions {
    display: flex;
    gap: 10px;
    flex-direction: row-reverse;
    margin-top: 20px;
}

/* الأزرار */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #1e40af;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--border-color);
    color: var(--text-color);
}

.btn-secondary:hover {
    background: #d1d5db;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-small {
    padding: 8px 12px;
    font-size: 12px;
}

/* الجداول */
.table-responsive {
    overflow-x: auto;
    margin-bottom: 20px;
}

.data-table,
.operations-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    box-shadow: var(--shadow);
    border-radius: 8px;
    overflow: hidden;
}

.data-table th,
.operations-table th {
    background: var(--primary-color);
    color: white;
    padding: 15px;
    text-align: right;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

.data-table td,
.operations-table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
}

.data-table tbody tr:hover,
.operations-table tbody tr:hover {
    background: var(--bg-light);
}

.data-table tbody tr:last-child td,
.operations-table tbody tr:last-child td {
    border-bottom: none;
}

/* ملخص الطلب */
.summary-section {
    background: linear-gradient(135deg, rgba(30, 58, 138, 0.05) 0%, rgba(59, 130, 246, 0.05) 100%);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: white;
    border-radius: 6px;
    border-right: 3px solid var(--accent-color);
}

.summary-item span:first-child {
    font-weight: 600;
    color: var(--text-color);
}

.summary-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
}

/* محتوى الخطاب الرسمي */
.letter-content {
    background: transparent;
    padding: 40px;
    line-height: 2;
    direction: rtl;
    text-align: right;
    font-size: 14px;
    color: #000;
    border: none;
    border-radius: 0;
    margin-top: 20px;
    min-height: 100vh;
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: scroll;
    position: relative;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    color-adjust: exact;
}

/* إزالة الطبقة الشفافة - الخلفية تظهر بشكل كامل */
.letter-content::before {
    display: none;
}

/* المحتوى فوق الطبقة الشفافة */
.letter-header,
.letter-date,
.letter-recipient,
.letter-body,
.letter-table,
.letter-signature {
    position: relative;
    z-index: 2;
}

.letter-header {
    text-align: center;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 20px;
}

.letter-header h2 {
    font-size: 18px;
    margin-bottom: 10px;
    color: var(--primary-color);
}

.letter-date {
    text-align: left;
    margin-bottom: 20px;
    color: var(--text-light);
}

.letter-recipient {
    margin-bottom: 20px;
    line-height: 1.8;
}

.letter-recipient p {
    margin-bottom: 10px;
}

.letter-body {
    margin: 20px 0;
    line-height: 2;
}

.letter-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

.letter-table th,
.letter-table td {
    border: 1px solid var(--border-color);
    padding: 12px;
    text-align: right;
}

.letter-table th {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

.letter-table tbody tr:nth-child(odd) {
    background: var(--bg-light);
}

.letter-signature {
    margin-top: 40px;
    text-align: center;
}

.letter-signature p {
    margin: 20px 0;
}

.signature-line {
    border-top: 1px solid var(--text-color);
    width: 200px;
    margin: 40px auto;
}

/* النماذج المدمجة داخل الجدول */
.inline-form {
    display: flex;
    gap: 10px;
    flex-direction: row-reverse;
}

.inline-form input {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 12px;
}

.inline-form .btn {
    padding: 8px 12px;
    font-size: 12px;
}

/* حقول الحساب المدمجة */
.account-field {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 15px;
    padding: 15px;
    background: var(--bg-light);
    border-radius: 6px;
    border-left: 3px solid var(--secondary-color);
}

.account-input-group {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    align-items: center;
}

.account-select {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: white;
    direction: rtl;
}

/* النافذة المنبثقة */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    direction: rtl;
}

.modal.show {
    display: block;
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 30px;
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 900px;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    overflow-y: auto;
}

.close {
    color: var(--text-light);
    float: left;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close:hover {
    color: var(--text-color);
}

/* رسائل الحالة */
.message {
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-weight: 600;
}

.message.success {
    background: #d1fae5;
    color: #065f46;
    border-left: 4px solid var(--success-color);
}

.message.error {
    background: #fee2e2;
    color: #7f1d1d;
    border-left: 4px solid var(--danger-color);
}

.message.warning {
    background: #fef3c7;
    color: #78350f;
    border-left: 4px solid var(--warning-color);
}

/* الخطوط الفارغة */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 16px;
    margin-bottom: 20px;
}

/* مؤشر الحفظ التلقائي */
.auto-save-indicator {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: rgba(16, 185, 129, 0.9);
    color: white;
    padding: 12px 16px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: fadeInOut 2s ease-in-out forwards;
    z-index: 999;
    opacity: 0;
}

.auto-save-indicator.show {
    animation: fadeInOut 2s ease-in-out forwards;
}

.auto-save-indicator .save-icon {
    font-size: 16px;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateY(10px); }
    10% { opacity: 1; transform: translateY(0); }
    90% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(10px); }
}

/* للشاشات الصغيرة */
@media (max-width: 480px) {
    .auto-save-indicator {
        left: 10px;
        right: 10px;
        bottom: 10px;
        font-size: 11px;
        padding: 10px 12px;
    }
}
    .container {
        padding: 10px;
    }

    .header {
        padding: 25px 15px;
    }

    .header-content h1 {
        font-size: 24px;
    }

    .header-content p {
        font-size: 14px;
    }

    .nav-tabs {
        flex-direction: column-reverse;
    }

    .nav-btn {
        min-width: auto;
    }

    .section {
        padding: 20px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-value {
        font-size: 20px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        width: 95%;
        margin: 20% auto;
        padding: 15px;
    }

    .letter-content {
        padding: 20px;
        font-size: 12px;
    }

    .form-actions {
        flex-direction: column-reverse;
    }

    .form-actions .btn {
        width: 100%;
    }

    table {
        font-size: 12px;
    }

    th, td {
        padding: 8px !important;
    }
}

@media (max-width: 480px) {
    .header-content h1 {
        font-size: 18px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .nav-tabs {
        gap: 5px;
    }

    .section {
        padding: 15px;
    }

    .btn {
        width: 100%;
        text-align: center;
    }
}

/* للطباعة */
@media print {
    body {
        background: white;
    }

    .container {
        padding: 0;
    }

    .header,
    .nav-tabs,
    .form-actions,
    .modal-content > button {
        display: none;
    }

    .letter-content {
        box-shadow: none;
        border: none;
        max-height: none;
        overflow: visible;
        width: 100%;
        min-height: 100vh;
        background-size: 100% 100% !important;
        background-repeat: no-repeat !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    .modal-content {
        margin: 0;
        padding: 0;
        width: 100%;
        box-shadow: none;
    }

    .modal {
        position: static;
        overflow: visible;
    }
}
