/* ==========================================================
   ERP ECHO — Unified Admin Layout (v1.2 — Dec 2025)
   تصميم احترافي موحد — ثابت في التمرير + استجابة كاملة
   ========================================================== */


/* 🌐 Reset أساسي */

* {
    font-family: "Cairo", sans-serif;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Cairo", sans-serif;
    background: #f3f6f9;
    color: #222;
}


/* 🧱 الحاويات العامة الموحّدة */

.category-wrapper,
.product-wrapper,
.purchase-wrapper,
.page-wrapper {
    background: #fff;
    padding: 25px;
    border-radius: 14px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);

    max-width: 95%;
}


/* 🧩 العناوين الرئيسية */

.content-wrapper h1,
.content-wrapper h2,
.product-wrapper h1,
.purchase-wrapper h1,
.purchase-wrapper h2 {
    color: #0b4f6c;
    margin-bottom: 15px;
    font-size: 1.5rem;
    border-right: 4px solid #0b4f6c;
    padding-right: 10px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.content-wrapper h1 i,
.content-wrapper h2 i {
    color: #0b4f6c;
}


/* ===============================
   🔹 شريط التحكم العلوي (Top Bar)
   =============================== */

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}


/* ===============================
   🔹 الأزرار العامة
   =============================== */

.btn {
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    transition: 0.2s;
}

.btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn.primary {
    background: #0b4f6c;
    color: #fff;
}

.btn.secondary {
    background: #6b7280;
    color: #fff;
}

.btn.success {
    background: #22c55e;
    color: #fff;
}

.btn.warning {
    background: #f59e0b;
    color: #fff;
}

.btn.danger {
    background: #dc2626;
    color: #fff;
}


/* ===============================
   🔍 مربع البحث الموحّد
   =============================== */

.search-box {
    position: relative;
    flex: 1;
    min-width: 250px;
}

.search-box input {
    width: 100%;
    padding: 10px 36px 10px 12px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    font-size: 14px;
    transition: 0.2s;
}

.search-box input:focus {
    border-color: #0b4f6c;
    outline: none;
    box-shadow: 0 2px 6px rgba(11, 79, 108, 0.1);
}

.search-box i {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #6b7280;
    pointer-events: none;
}


/* ===============================
   📋 الجداول العامة (ثابتة في Scroll)
   =============================== */


/* ✅ الغلاف المسئول عن الـ Scroll */

.table-scroll {
    display: block;
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: auto;
    /* ✅ يسمح بالتحريك بالعرض */
    scrollbar-width: thin;
    scrollbar-color: rgba(11, 79, 108, 0.4) transparent;
}


/* ✅ الجدول نفسه */

.table-basic {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    margin-top: 10px;
    border-radius: 10px;
    background: #fff;
    min-width: 850px;
    /* يمنع الانكماش على الشاشات الصغيرة */
}


/* الرأس الثابت */

.table-basic thead th {
    position: sticky;
    top: 0;
    background: #0b4f6c;
    color: #fff;
    text-align: center;
    padding: 10px;
    z-index: 2;
}


/* الصفوف */

.table-basic td,
.table-basic th {
    padding: 10px;
    text-align: center;
    border-bottom: 1px solid #eee;
    background: #fff;
}

.table-basic tr:hover td {
    background: #f9fafb;
}


/* 🎯 Scrollbar ناعم */

.table-scroll::-webkit-scrollbar {
    width: 6px;
}

.table-scroll::-webkit-scrollbar-thumb {
    background-color: rgba(11, 79, 108, 0.4);
    border-radius: 10px;
}

.table-scroll::-webkit-scrollbar-thumb:hover {
    background-color: rgba(11, 79, 108, 0.7);
}


/* 🎯 أزرار التحكم داخل الجدول */

.btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 15px;
    margin: 0 3px;
    border: none;
    cursor: pointer;
    transition: transform 0.1s ease-in-out, background 0.2s;
}

.btn-action:hover {
    transform: scale(1.05);
}

.btn-action.red {
    background: #dc2626;
    color: #fff;
}

.btn-action.orange {
    background: #f59e0b;
    color: #fff;
}

.btn-action.green {
    background: #16a34a;
    color: #fff;
}

.btn-action.blue {
    background: #2563eb;
    color: #fff;
}


/* ===============================
   🪟 صناديق الملخص (Summary Cards)
   =============================== */

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.summary-cards .card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 18px 20px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s;
}

.summary-cards .card:hover {
    transform: translateY(-3px);
}

.summary-cards .card h4 {
    color: #0b4f6c;
    font-weight: 700;
    margin-bottom: 5px;
}

.summary-cards .card p {
    font-size: 18px;
    color: #222;
    font-weight: bold;
}


/* ===============================
   📱 Responsive
   =============================== */

@media (max-width: 768px) {
    .top-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        order: 3;
    }

    .summary-cards {
        grid-template-columns: 1fr 1fr;
    }

    .table-basic {
        font-size: 13px;
        min-width: 700px;
    }
}


/* ===============================
   💡 Bottom Sheet / Modal
   =============================== */

#stockAdjustModal {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 9999;
}

.sa-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.sa-card {
    position: relative;
    z-index: 10000;
    background: #fff;
    width: 600px;
    max-width: 95%;
    margin: 80px auto;
    padding: 25px 20px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    animation: fadeIn 0.2s ease;
}

.sa-card h3 {
    text-align: center;
    margin-bottom: 12px;
    color: #0b4f6c;
}

.sa-row {
    margin-bottom: 10px;
}

.two-cols {
    display: flex;
    gap: 10px;
}

.two-cols>div {
    flex: 1;
}

.sa-row label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    color: #0b4f6c;
}

.sa-row input,
.sa-row select,
.sa-row textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
}

.sa-actions {
    text-align: center;
    margin-top: 12px;
}

.sa-actions .btn {
    padding: 8px 14px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    margin: 0 5px;
}

.btn.success {
    background: #16a34a;
    color: #fff;
}

.btn.secondary {
    background: #6b7280;
    color: #fff;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =====================================
   Compact Form Layout (Top Sections)
===================================== */

.compact-form select,
.compact-form input,
.compact-form textarea {
    height: 42px;
    font-size: 14px;
}

/* شبكة عامة */
.compact-form .grid-2 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    align-items: center;
}

/* المورد + المخزن */
.compact-form select[name="warehouse_id"],
.compact-form select[name="supplier_id"] {
    grid-column: span 2;
}

/* اسم المورد */
.compact-form input[name="supplier_name"] {
    grid-column: span 2;
}

/* الهاتف + الإيميل */
.compact-form input[name="supplier_phone"],
.compact-form input[name="supplier_email"] {
    grid-column: span 1;
}

/* العنوان + الملاحظات */
.compact-form input[name="supplier_address"],
.compact-form textarea[name="supplier_note"] {
    grid-column: span 2;
}

/* موبايل */
@media (max-width: 768px) {
    .compact-form .grid-2 {
        grid-template-columns: 1fr 1fr;
    }

    .compact-form select,
    .compact-form input,
    .compact-form textarea {
        grid-column: span 2 !important;
    }
}

/* ===============================
   FIX LAYOUT WIDTH
=============================== */

.layout {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    min-height: 100vh;
    padding: 30px;


    /* نفس عرض السايدبار */
    background: #f3f7fc;
    overflow-x: auto;
}

.content-wrapper {
    max-width: 100%;
    margin: 0;
}

/* ==========================================================
   📄 PURCHASE VIEW ENHANCEMENTS — Echo ERP
   ========================================================== */


/* ===============================
   🧾 Invoice Header Cards
=============================== */

.invoice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 18px;
    margin-bottom: 20px;
}

.info-card {
    background: #fff;
    padding: 18px 20px;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
}

.info-card h4 {
    font-size: 15px;
    margin-bottom: 12px;
    color: #0b4f6c;
    font-weight: 700;
}

.info-card p {
    margin-bottom: 6px;
    font-size: 14px;
}

.info-card strong {
    color: #0b4f6c;
}


/* ===============================
   🟢 Payment Status Badge
=============================== */

.badge {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
}

.badge.paid {
    background: #dcfce7;
    color: #166534;
}

.badge.partial {
    background: #fef9c3;
    color: #854d0e;
}

.badge.unpaid {
    background: #fee2e2;
    color: #991b1b;
}


/* ===============================
   📦 Items Table Scroll
=============================== */

.items-scroll {
    max-height: 420px;
    overflow-y: auto;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
}

.items-scroll::-webkit-scrollbar {
    width: 6px;
}

.items-scroll::-webkit-scrollbar-thumb {
    background: rgba(11, 79, 108, 0.4);
    border-radius: 10px;
}

.items-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(11, 79, 108, 0.7);
}


/* ===============================
   💰 Totals Box
=============================== */

.totals-box {
    background: #fff;
    margin-top: 20px;
    padding: 18px 20px;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    gap: 15px;
    flex-wrap: wrap;
}

.totals-box div {
    flex: 1;
    min-width: 150px;
    text-align: center;
}

.totals-box span {
    display: block;
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 5px;
}

.totals-box strong {
    font-size: 18px;
    font-weight: 700;
    color: #0b4f6c;
}

.totals-box .due strong {
    color: #dc2626;
}


/* ===============================
   🖨 Print Mode (احترافي)
=============================== */

@media print {

    /* اخفاء السايدبار والهيدر */
    .sidebar,
    .main-sidebar,
    .header,
    .top-bar,
    .actions,
    nav,
    aside {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .layout,
    .main-content {
        padding: 0 !important;
        margin: 0 !important;
    }

    .purchase-wrapper {
        box-shadow: none !important;
        border: none !important;
        margin: 0 !important;
        padding: 10px 20px !important;
        width: 100% !important;
    }

    .table-basic thead th {
        background: #0b4f6c !important;
        color: #fff !important;
    }

    .items-scroll {
        max-height: none !important;
        overflow: visible !important;
        border: none !important;
    }

}


/* ===============================
   📱 Responsive Improvements
=============================== */

@media (max-width: 768px) {

    .totals-box {
        flex-direction: column;
        text-align: center;
    }

    .invoice-grid {
        grid-template-columns: 1fr;
    }

}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px
}

.summary-row.total {
    font-size: 17px;
    font-weight: 700;
    color: #0b4f6c
}

.summary-row input {
    width: 140px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid #ccc;
    text-align: center
}

.purchase-top-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 420px;
    gap: 20px;
    align-items: start
}

@media (max-width:1200px) {
    .purchase-top-grid {
        grid-template-columns: 1fr
    }
}

.select2-container {
    width: 100% !important;
    font-family: "Cairo", system-ui, sans-serif;
    font-size: 14px
}

.select2-container--default .select2-selection--single {
    height: 44px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #fff;
    display: flex;
    align-items: center;
    padding: 0 10px;
    transition: all .2s ease
}

.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: #0b4f6c;
    box-shadow: 0 0 0 3px rgba(11, 79, 108, .12)
}

.select2-selection__rendered {
    color: #0f172a;
    padding-right: 6px !important;
    line-height: 44px !important;
    text-align: right
}

.select2-selection__arrow {
    height: 100%;
    right: 8px !important;
    left: auto !important
}

.select2-search--dropdown .select2-search__field {
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    padding: 8px 10px;
    font-family: "Cairo", system-ui, sans-serif
}

.select2-dropdown {
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 12px 30px rgba(0, 0, 0, .12);
    overflow: hidden
}

.select2-results__option {
    padding: 10px 12px;
    font-size: 14px;
    text-align: right;
    cursor: pointer
}

.select2-results__option--highlighted {
    background: #0b4f6c !important;
    color: #fff !important
}

.select2-results__option--selected {
    background: #f1f5f9;
    color: #0f172a;
    font-weight: 600
}

.select2-selection__placeholder {
    color: #94a3b8
}

.select2-container--default .select2-selection--single {
    direction: rtl
}

.table-basic .select2-container {
    min-width: 220px
}

.category-select,
.sub-category-select,
.product-select {
    width: 100%;
}

#itemTable td {
    vertical-align: middle;
}

.field-hint {
    margin-top: 8px;
    font-size: 13px;
    color: #64748b;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px;
}

.field-hint.is-hidden {
    display: none;
}

#addItemBtn:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.purchase-top-grid {
    display: grid;
    grid-template-columns: minmax(420px, 1.35fr) minmax(320px, 1fr);
    gap: 22px;
    align-items: stretch;
    margin-bottom: 22px;
}

.card-erp {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    padding: 22px;
    display: flex;
    flex-direction: column;
    min-height: 100%;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .05);
}

.card-erp h3,
.card-erp .card-header h4 {
    margin: 0 0 16px;
    font-size: 18px;
    font-weight: 800;
    color: #0b4f6c;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #eef2f7;
    padding-bottom: 10px;
}

.card-erp .card-body {
    flex: 1;
}

.card-erp .card-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid #eef2f7;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.summary-card .card-header {
    padding: 0;
    border-bottom: none;
    margin-bottom: 8px;
}

.summary-card .card-body {
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
}

.summary-row.total {
    font-size: 19px;
    font-weight: 800;
    color: #0b4f6c;
    padding: 10px 0;
}

.summary-row input {
    width: 160px;
    height: 44px;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid #d1d5db;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
}

.supplier-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.supplier-grid textarea {
    grid-column: 1 / -1;
    min-height: 54px;
    resize: vertical;
}

.actions .btn,
.card-footer .btn {
    min-height: 46px;
    padding: 0 18px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
}

.summary-card .card-footer .btn {
    flex: 1 1 160px;
}

#warehouseSelect,
#supplierSelect,
.supplier-grid input,
.supplier-grid textarea {
    width: 100%;
    min-height: 44px;
    border-radius: 12px;
}

.form-section {
    margin-bottom: 0;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
}

.table-basic {
    width: 100%;
}

#addItemBtn {
    min-height: 46px;
    padding: 0 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 800;
}

@media (max-width: 1200px) {
    .purchase-top-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .card-erp {
        padding: 16px;
        border-radius: 14px;
    }

    .supplier-grid {
        grid-template-columns: 1fr;
    }

    .summary-row {
        flex-direction: column;
        align-items: stretch;
    }

    .summary-row input {
        width: 100%;
    }

    .summary-card .card-footer .btn,
    .actions .btn,
    .card-footer .btn {
        width: 100%;
        flex: 1 1 100%;
    }
}

.btn.success {
    box-shadow: 0 8px 20px rgba(34, 197, 94, .18);
}

.btn.secondary {
    background: #667085;
    color: #fff;
}

.btn.primary {
    box-shadow: 0 8px 20px rgba(11, 79, 108, .15);
}