/* =====================================================
   Invoice Generator - Unified Design System
   (مع تصغير عرض الأزرار)
   ===================================================== */

/* ===== Container Base ===== */
.tool-wrapper[data-tool="pdf-invoice-generator"] {
    font-family: 'Segoe UI', Roboto, system-ui, sans-serif;
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 1rem;
    color: #1e293b;
}

/* ===== الحاوية الرئيسية ===== */
.invoice-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

/* ===== الجانب الأيسر: النموذج ===== */
.invoice-form {
    background: #ffffff;
    border-radius: 1rem;
    padding: 1.5rem 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    border: 1px solid #e9edf2;
}

.invoice-form h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
    margin: 1.2rem 0 0.8rem 0;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid #e9edf2;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.invoice-form h2:first-of-type {
    margin-top: 0;
}

.invoice-form h2 i {
    color: #0067b8;
}

/* ===== حقول النموذج ===== */
.form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.75rem;
    color: #1e293b;
    margin-bottom: 0.2rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.form-group label i {
    width: 1rem;
    color: #0067b8;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.4rem 0.7rem;
    border: 1px solid #d1d9e6;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    color: #1e293b;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: #0067b8;
    box-shadow: 0 0 0 3px rgba(0, 103, 184, 0.12);
    outline: none;
}

.form-group textarea {
    min-height: 40px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* ===== أزرار رفع الملفات (عرض أقل) ===== */
.upload-file-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: auto;
    max-width: 220px;
    margin: 0 auto;
    padding: 0.3rem 1.2rem;
    background: #0067b8;
    color: #ffffff;
    border: none;
    border-radius: 2rem;
    font-weight: 600;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
    height: 32px;
}

.upload-file-btn:hover {
    background: #005499;
}

.upload-file-btn i {
    font-size: 0.85rem;
}

.selected-file-name {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.7rem;
    color: #64748b;
    font-weight: 500;
    text-align: center;
    min-height: 1rem;
}

/* ===== جدول العناصر ===== */
.table-wrapper {
    overflow-x: auto;
    margin: 0.4rem 0 0.75rem 0;
    border-radius: 0.5rem;
    border: 1px solid #e9edf2;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.items-table th {
    background: #f8fafc;
    padding: 0.35rem 0.25rem;
    text-align: left;
    font-weight: 600;
    color: #0f172a;
    border-bottom: 2px solid #e9edf2;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.items-table td {
    padding: 0.2rem 0.15rem;
    vertical-align: middle;
    border-bottom: 1px solid #e9edf2;
}

.items-table input,
.items-table select {
    width: 100%;
    padding: 0.2rem 0.35rem;
    border: 1px solid #d1d9e6;
    border-radius: 0.3rem;
    font-size: 0.78rem;
    background: #fff;
    height: 28px;
}

.items-table input:focus,
.items-table select:focus {
    border-color: #0067b8;
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 103, 184, 0.12);
}

.btn-icon {
    background: transparent;
    border: none;
    color: #dc2626;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.15rem 0.3rem;
    border-radius: 0.3rem;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: #fef2f2;
}

/* ===== زر إضافة عنصر (عرض أقل) ===== */
.btn-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: auto;
    max-width: 200px;
    margin: 0.3rem auto 0.75rem auto;
    padding: 0.3rem 1.2rem;
    background: #f1f5f9;
    border: 1px dashed #0067b8;
    border-radius: 2rem;
    font-weight: 600;
    font-size: 0.78rem;
    color: #0067b8;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    height: 30px;
}

.btn-add:hover {
    background: #f0f7ff;
    border-color: #005499;
}

.btn-add i {
    font-size: 0.7rem;
}

/* ===== الإجماليات ===== */
.totals {
    background: #f8fafc;
    border-radius: 0.75rem;
    padding: 0.75rem 1.2rem;
    margin: 0.75rem 0;
    border: 1px solid #e9edf2;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    font-size: 0.85rem;
    color: #1e293b;
}

.total-row.grand {
    font-weight: 700;
    font-size: 1rem;
    border-top: 2px solid #d1d9e6;
    padding-top: 0.4rem;
    margin-top: 0.2rem;
    color: #0f172a;
}

/* ===== زر توليد PDF (عرض أقل ووسطي) ===== */
.btn-generate {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: auto;
    max-width: 320px;
    margin: 1.2rem auto 0 auto;
    padding: 0.5rem 2rem;
    background: linear-gradient(135deg, #0067b8 0%, #005499 100%);
    color: #ffffff;
    border: none;
    border-radius: 2rem;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
    height: 40px;
}

.btn-generate:hover {
    background: linear-gradient(135deg, #005499 0%, #003d73 100%);
    box-shadow: 0 4px 12px rgba(0, 103, 184, 0.3);
}

.btn-generate i {
    font-size: 0.9rem;
}

/* ===== الجانب الأيمن: المعاينة ===== */
.invoice-preview {
    background: #ffffff;
    border-radius: 1rem;
    padding: 1.5rem 1.5rem 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    border: 1px solid #e9edf2;
    position: sticky;
    top: 1rem;
    display: flex;
    flex-direction: column;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.preview-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.preview-header h2 i {
    color: #0067b8;
}

.preview-badge {
    background: #dbeafe;
    color: #0067b8;
    padding: 0.15rem 0.7rem;
    border-radius: 1rem;
    font-size: 0.7rem;
    font-weight: 600;
}

.preview-content {
    background: #f8fafc;
    border-radius: 0.75rem;
    border: 1px solid #e9edf2;
    padding: 0.75rem;
    min-height: 350px;
    overflow-y: auto;
    flex: 1;
}

.preview-card {
    background: #ffffff;
    border-radius: 0.5rem;
    padding: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.preview-placeholder {
    text-align: center;
    padding: 2rem 1rem;
    color: #94a3b8;
}

.preview-placeholder i {
    font-size: 2.5rem;
    color: #cbd5e1;
    display: block;
    margin-bottom: 0.4rem;
}

.preview-placeholder p {
    font-size: 0.85rem;
}

/* ===== التجاوب مع الشاشات المختلفة ===== */
@media (max-width: 1024px) {
    .invoice-container {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .invoice-preview {
        position: static;
    }
}

@media (max-width: 768px) {
    .tool-wrapper {
        padding: 0 0.5rem;
    }

    .invoice-form {
        padding: 1rem 1.2rem;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .invoice-preview {
        padding: 1rem;
    }

    .preview-content {
        min-height: 250px;
        max-height: 350px;
    }

    /* تصغير عرض الأزرار في الشاشات المتوسطة */
    .upload-file-btn {
        max-width: 180px;
    }

    .btn-add {
        max-width: 160px;
    }

    .btn-generate {
        max-width: 260px;
    }
}

@media (max-width: 480px) {
    .invoice-form {
        padding: 0.75rem;
    }

    .invoice-form h2 {
        font-size: 0.95rem;
    }

    .form-group label {
        font-size: 0.65rem;
    }

    .items-table {
        font-size: 0.7rem;
    }

    .items-table th,
    .items-table td {
        padding: 0.15rem 0.1rem;
    }

    .items-table input,
    .items-table select {
        font-size: 0.65rem;
        padding: 0.1rem 0.2rem;
        height: 24px;
    }

    /* جعل الأزرار بعرض كامل في الشاشات الصغيرة جداً */
    .upload-file-btn {
        max-width: 100%;
        width: 100%;
    }

    .btn-add {
        max-width: 100%;
        width: 100%;
    }

    .btn-generate {
        max-width: 100%;
        width: 100%;
        padding: 0.4rem 1rem;
        height: 36px;
        font-size: 0.8rem;
    }

    .preview-header {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .preview-header h2 {
        font-size: 0.9rem;
    }

    .selected-file-name {
        font-size: 0.65rem;
    }

    .totals {
        padding: 0.5rem 0.8rem;
    }

    .total-row {
        font-size: 0.75rem;
    }

    .total-row.grand {
        font-size: 0.9rem;
    }
}

/* ===== تنسيق الطباعة ===== */
@media print {
    .invoice-form {
        display: none !important;
    }

    .invoice-container {
        display: block !important;
        padding: 0 !important;
        gap: 0 !important;
    }

    .invoice-preview {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        position: static !important;
    }

    .preview-header {
        background: white !important;
        border-bottom: 1px solid #e5e7eb !important;
    }

    .preview-badge {
        background: #0067b8 !important;
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .preview-content {
        background: white !important;
        max-height: none !important;
        overflow-y: visible !important;
        border: none !important;
        padding: 0 !important;
    }

    .preview-card {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
    }
}