/* 1. فراخوانی فونت وزیرمتن (Vazirmatn) از گوگل فونت - لینک اصلاح شده */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@100..900&display=swap');

:root {
    /* 2. رنگ‌بندی هویت بصری (Brand Identity) */
    /* لطفا کد هگز رنگ‌های خود را از فایل Visual-identity.jpg استخراج و اینجا جایگزین کنید */
    --brand-primary: #1C3FAA;    /* رنگ اصلی (آبی پرشین) - پیشنهادی */
    --brand-secondary: #2F3542;  /* رنگ دوم (طوسی تیره) */
    --brand-accent: #00D09C;     /* رنگ تاکید (سبز نعنایی) - در صورت وجود */
    
    /* تنظیمات مدرن‌سازی */
    --border-radius-base: 12px;
    --box-shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.08);
}

/* 3. تنظیمات فونت و اعداد فارسی */
body, h1, h2, h3, h4, h5, h6, .btn, .navbar-brand, .form-control {
    font-family: 'Vazirmatn', sans-serif !important;
}

/* اگر می‌خواهید اعداد انگلیسی (123) به فارسی (۱۲۳) تبدیل شوند، خط زیر را فعال نگه دارید */
body {
    font-feature-settings: "ss01"; 
}

/* 4. مدرن‌سازی ظاهر قالب (Flat & Modern UI) */

/* هدر و نوار ناوبری */
.header .navbar {
    background-color: #fff !important;
    box-shadow: 0 2px 15px rgba(0,0,0,0.05);
    padding: 15px 0;
}
.navbar-main .navbar-nav > li > a {
    font-weight: 500;
    color: var(--brand-secondary) !important;
}

/* کارت‌ها و باکس‌ها */
.card, .panel {
    border: none !important;
    border-radius: var(--border-radius-base) !important;
    box-shadow: var(--box-shadow-soft) !important;
    transition: transform 0.2s;
}
.card:hover {
    transform: translateY(-4px);
}

/* دکمه‌های اصلی */
.btn-primary {
    background-color: var(--brand-primary) !important;
    border-color: var(--brand-primary) !important;
    border-radius: 8px;
    padding: 10px 24px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(28, 63, 170, 0.2); /* سایه همرنگ برند */
}
.btn-primary:hover {
    filter: brightness(1.1);
    box-shadow: 0 6px 15px rgba(28, 63, 170, 0.3);
}

/* فیلدهای ورودی */
.form-control {
    border-radius: 8px !important;
    border: 1px solid #e0e0e0;
    padding: 12px;
    background-color: #f9f9f9;
}
.form-control:focus {
    background-color: #fff;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(28, 63, 170, 0.1);
}

/* سایدبار (منوی کناری) */
.sidebar .panel-sidebar {
    border-radius: var(--border-radius-base);
    overflow: hidden;
}
.sidebar .panel-sidebar > .panel-heading {
    background-color: var(--brand-secondary) !important;
    color: #fff;
}

/* فوتر مدرن تیره */
section#footer {
    background-color: #1a1a1a; /* خاکستری خیلی تیره */
    color: #bbb;
    padding-top: 60px;
}
section#footer a {
    color: #fff;
}
.footer-copyright {
    background-color: #000;
    padding: 20px 0;
}
/* --- استایل فاکتور رسمی + دکمه‌های مدرن بالای صفحه --- */

/* 1. نوار ابزار بالا (Top Bar) */
.invoice-top-bar {
    background-color: #fff;
    padding: 15px 0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    margin-bottom: 30px;
    border-bottom: 1px solid #eee;
}

/* 2. استایل پایه دکمه‌ها (مشترک برای همه) */
.btn-invoice-action,
.inline-pay-btn input[type="submit"],
.inline-pay-btn button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 8px;
    font-family: 'Vazirmatn', sans-serif;
    font-weight: 500;
    font-size: 0.95rem;
    text-decoration: none !important;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.08);
    margin: 5px;
    height: 45px; /* ارتفاع ثابت برای هم‌ترازی */
    line-height: 1;
}

.btn-invoice-action i {
    margin-left: 8px; /* فاصله آیکون از متن */
}

/* 3. رنگ‌بندی دکمه‌ها */

/* دکمه بازگشت (طوسی) */
.btn-back {
    background-color: #f1f3f5;
    color: #495057;
}
.btn-back:hover {
    background-color: #e9ecef;
    transform: translateY(-2px);
    color: #212529;
}

/* دکمه پرینت (آبی تیره) */
.btn-print {
    background-color: #2F3542; /* رنگ دوم برند شما */
    color: #fff;
}
.btn-print:hover {
    background-color: #1e222b;
    transform: translateY(-2px);
    color: #fff;
    box-shadow: 0 6px 12px rgba(47, 53, 66, 0.3);
}

/* دکمه دانلود (آبی روشن/اصلی) */
.btn-download {
    background-color: #1C3FAA; /* رنگ اصلی برند شما */
    color: #fff;
}
.btn-download:hover {
    background-color: #153085;
    transform: translateY(-2px);
    color: #fff;
    box-shadow: 0 6px 12px rgba(28, 63, 170, 0.3);
}

/* دکمه پرداخت (سبز - ویژه) */
/* ما باید input داخل فرم را هدف بگیریم چون WHMCS فرم می‌سازد */
.inline-pay-btn {
    display: inline-block;
}
.inline-pay-btn input[type="submit"],
.inline-pay-btn button {
    background-color: #00D09C; /* رنگ سبز برند شما */
    color: #fff;
    font-size: 1rem;
    padding: 10px 30px; /* کمی پهن‌تر */
}
.inline-pay-btn input[type="submit"]:hover {
    background-color: #00b084;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 208, 156, 0.4);
}

/* --- استایل کاغذ فاکتور (بدون تغییر عمده نسبت به قبل) --- */
body.invoice-print-body {
    background-color: #555;
    font-family: 'Vazirmatn', Tahoma, sans-serif !important;
    font-size: 13px;
    padding-bottom: 50px;
    margin: 0;
}

.invoice-paper {
    background-color: #fff;
    width: 210mm;
    min-height: 297mm;
    margin: 20px auto;
    padding: 15mm;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    border: 1px solid #ddd;
    position: relative;
    direction: rtl;
    text-align: right;
}

.invoice-header-box {
    border: 2px solid #000;
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 20px;
}
.invoice-logo {
    max-height: 80px;
    max-width: 100%;
}
.invoice-title {
    font-size: 18px;
    font-weight: bold;
    margin: 0;
    color: #000;
}
.invoice-meta-data p { margin: 4px 0; }

.parties-container {
    display: flex;
    border: 2px solid #000;
    border-radius: 5px;
    margin-bottom: 20px;
}
.party-box { width: 50%; }
.party-box.seller { border-left: 1px solid #000; }
.box-title {
    background-color: #eee;
    color: #000;
    padding: 5px 10px;
    font-weight: bold;
    border-bottom: 1px solid #000;
    text-align: center;
}
.box-content { padding: 10px; }
.box-content ul { list-style: none; padding: 0; margin: 0; }
.box-content ul li { margin-bottom: 5px; }

/* رفع مشکل جدول */
.items-table-container { width: 100%; }
.items-table {
    width: 100% !important;
    border: 2px solid #000 !important;
    margin-bottom: 0 !important;
    border-collapse: collapse;
}
.items-table thead th {
    background-color: #eee !important;
    color: #000 !important;
    border: 1px solid #000 !important;
    text-align: center;
    padding: 10px;
}
.items-table tbody td {
    border: 1px solid #000 !important;
    padding: 10px !important;
    vertical-align: middle;
}

.invoice-footer-math {
    border: 2px solid #000;
    border-top: none;
    border-radius: 0 0 5px 5px;
}
.description-area {
    padding: 15px;
    border-left: 1px solid #000;
}
.totals-area table { width: 100%; margin: 0; }
.totals-area td {
    border: 1px solid #000;
    border-right: none; border-left: none;
    padding: 8px;
}
.grand-total-row td {
    background-color: #333 !important;
    color: #fff !important;
    font-size: 15px;
    font-weight: bold;
}

.signature-box {
    border: 1px dashed #999;
    border-radius: 8px;
    padding: 15px;
    margin: 0 15px;
    height: 140px;
}

.invoice-bottom-footer {
    border-top: 1px solid #ddd;
    padding-top: 15px;
    color: #888;
    font-size: 11px;
}

/* تنظیمات پرینت */
/* --- تنظیمات پرینت (نسخه نهایی: اصلاح جدول قیمت) --- */
@media print {
    /* 1. تنظیمات کاغذ */
    @page {
        size: A4 portrait;
        margin: 0;
    }

    html, body {
        width: 210mm;
        height: auto;
        background: #fff !important;
        margin: 0 !important;
        padding: 0 !important;
        font-size: 11pt;
    }

    /* 2. مخفی سازی */
    body * {
        visibility: hidden;
        height: 0;
        overflow: hidden;
    }

    /* 3. نمایش فاکتور */
    .invoice-paper, .invoice-paper * {
        visibility: visible !important;
        height: auto;
        overflow: visible;
    }

    /* 4. پوزیشن کاغذ */
    .invoice-paper {
        position: absolute;
        top: 0;
        right: 0;
        width: 190mm !important; /* عرض امن */
        max-width: 190mm !important;
        padding: 5mm 10mm !important;
        margin: 0 !important;
        border: none !important;
        background-color: transparent !important;
        z-index: 9999;
        transform: scale(0.95);
        transform-origin: top right;
    }

    /* 5. ستون‌بندی (اصلاح شده برای فضای بیشتر به قیمت) */
    .row {
        display: flex !important;
        flex-wrap: nowrap !important;
        direction: rtl !important;
        margin: 0 !important;
    }
    
    /* تنظیم دقیق عرض ستون‌ها */
    .col-4 { width: 33.33% !important; flex: 0 0 33.33% !important; }
    .col-6 { width: 50% !important; flex: 0 0 50% !important; }
    .col-12 { width: 100% !important; flex: 0 0 100% !important; }

    /* --- تغییر مهم: فضای بیشتر برای جدول قیمت --- */
    .description-area { 
        width: 55% !important; /* کم کردن عرض توضیحات */
        flex: 0 0 55% !important; 
    }
    .totals-area { 
        width: 45% !important; /* زیاد کردن عرض قیمت‌ها */
        flex: 0 0 45% !important; 
    }

    /* 6. استایل جدول‌ها */
    .items-table-container { 
        width: 100% !important; 
        display: block !important; 
        margin-top: 10px !important;
    }
    table, .table { 
        width: 100% !important; 
        border-collapse: collapse !important; 
    }

    /* 7. تنظیمات اختصاصی جدول قیمت (رفع مشکل کوچکی) */
    .totals-area table td {
        font-size: 11pt !important; /* فونت درشت‌تر */
        padding: 8px 10px !important; /* پدینگ بیشتر */
        white-space: nowrap !important; /* جلوگیری از شکستن خط */
    }
    .grand-total-row td {
        font-size: 13pt !important; /* فونت خیلی درشت برای مبلغ نهایی */
        padding: 12px 10px !important;
        font-weight: bold !important;
    }

    /* 8. رنگ‌ها */
    .bg-light { background-color: #f8f9fa !important; -webkit-print-color-adjust: exact; }
    .bg-dark { background-color: #333 !important; color: #fff !important; -webkit-print-color-adjust: exact; }
    .table-bordered td, .table-bordered th { border: 1px solid #000 !important; }

    /* 9. مخفی کردن اضافات */
    .d-print-none, .invoice-top-bar, .payment-action-bottom, header, footer, .sidebar {
        display: none !important;
    }
    
    /* 10. فواصل */
    .invoice-header-box, .parties-container, .items-table-container, .invoice-footer-math {
        margin-bottom: 15px !important;
    }
}
/* --- تنظیمات موبایل (رفع اسکرول و اصلاح دکمه‌ها) --- */
@media (max-width: 768px) {
    
    /* 1. رفع اسکرول افقی مزاحم */
    body, html {
        overflow-x: hidden; /* جلوگیری از اسکرول افقی کلی */
    }
    .container, .container-fluid {
        padding-right: 15px;
        padding-left: 15px;
        overflow-x: hidden;
    }

    /* 2. استایل نوار دکمه‌های بالا در موبایل */
    .invoice-top-bar {
        padding: 10px 5px;
    }
    
    /* کانتینر دکمه‌ها را فلکس می‌کنیم */
    .invoice-top-bar .col-md-8, 
    .invoice-top-bar .col-md-4 {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        padding: 0 5px !important;
    }

    /* تنظیم سایز دکمه‌ها: کنار هم قرار گرفتن */
    .btn-invoice-action {
        flex: 1 1 40%; /* عرض حدود نصف صفحه */
        margin: 5px !important;
        font-size: 12px !important; /* فونت کمی ریزتر */
        padding: 8px 5px !important;
        height: 40px !important;
        white-space: nowrap;
    }

    /* دکمه پرداخت همیشه تمام عرض باشد */
    .inline-pay-btn {
        width: 100%;
        margin: 5px;
        order: -1; /* اولویت نمایش در بالا */
    }
    .inline-pay-btn input[type="submit"], 
    .inline-pay-btn button {
        width: 100%;
        padding: 10px !important;
    }

    /* دکمه بازگشت در پایین‌ترین قسمت */
    .btn-back {
        flex: 1 1 100%; /* تمام عرض */
        background-color: transparent;
        border: 1px solid #ddd;
        margin-top: 10px !important;
        color: #777;
    }

    /* 3. بهینه‌سازی کاغذ فاکتور برای موبایل */
    .invoice-paper {
        width: 100% !important;
        margin: 0 auto 20px auto !important; /* فاصله از پایین */
        padding: 15px !important; /* حاشیه داخلی کمتر */
        border-radius: 0; /* حذف گردی گوشه برای استفاده حداکثری */
        box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    }

    /* 4. کوچک کردن هدر فاکتور در موبایل */
    .invoice-header-box {
        padding: 10px;
    }
    .invoice-header-box .row {
        display: flex;
        flex-direction: column;
        text-align: center !important;
    }
    .invoice-header-box .col-4 {
        max-width: 100%;
        flex: 0 0 100%;
        margin-bottom: 10px;
        text-align: center !important;
    }
    .invoice-logo {
        max-height: 60px;
        margin: 0 auto; /* وسط چین کردن لوگو */
        display: block;
    }

    /* 5. ریسپانسیو کردن جدول‌ها */
    .table-responsive {
        border: 0;
        overflow-x: auto; /* اسکرول فقط برای جدول */
    }
    .items-table, .totals-area table {
        font-size: 12px;
    }
    
    /* 6. چیدمان ستون‌های پایین فاکتور (توضیحات و قیمت) */
    .invoice-footer-math {
        flex-direction: column-reverse; /* قیمت بالا، توضیحات پایین */
    }
    .col-5.totals-area, 
    .col-7.description-area {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
        border-left: none;
    }
    .description-area {
        border-top: 1px solid #000;
        padding-top: 15px;
    }
    
    /* 7. بخش امضاها */
    .signatures-section .col-6 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 20px;
    }
}