/* فواتير الشراء — تخطيط POS احترافي (مثل سطح المكتب) */
.purchase-page {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
    background: #eef2f7;
}

.purchase-page--editor {
    flex: 1 1 0;
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
}

.purchase-page--editor > .page-toolbar {
    flex-shrink: 0;
}

.purchase-page--editor > .page-toolbar {
    flex-shrink: 0;
}

.purchase-page--editor > .purchase-page__body {
    flex: 1 1 0;
    min-height: 0;
}

.purchase-page__body {
    flex: 1;
    min-height: 0;
    padding: 10px 12px 14px;
}

.purchase-page__body--editor {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 8px 10px 10px;
}

/* شريط تمرير واضح داخل أقسام الفاتورة */
.purchase-scroll {
    overflow: auto;
    scrollbar-gutter: stable;
    scrollbar-width: auto;
    scrollbar-color: #64748b #e8eef4;
}

.purchase-scroll::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.purchase-scroll::-webkit-scrollbar-track {
    background: linear-gradient(180deg, #f1f5f9 0%, #e8eef4 100%);
    border-radius: 10px;
    margin: 4px;
    border: 1px solid #e2e8f0;
}

.purchase-scroll::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #94a3b8 0%, #64748b 55%, #475569 100%);
    border-radius: 10px;
    border: 2px solid #e8eef4;
    min-height: 40px;
}

.purchase-scroll::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #0d9488 0%, #0f766e 55%, #115e59 100%);
    border-color: #ccfbf1;
}

/* ——— قائمة الفواتير ——— */
.purchase-list-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
    gap: 10px;
    min-height: calc(100vh - 168px);
}

.purchase-list-main {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.purchase-list-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
}

.purchase-list-head h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.purchase-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
}

.purchase-filter-pill {
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #334155;
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.purchase-filter-pill:hover {
    background: #eff6ff;
    border-color: #0d9488;
}

.purchase-filter-pill.is-active {
    background: rgba(13, 148, 136, 0.12);
    border-color: #0d9488;
    color: #0f766e;
}

.purchase-list-table-wrap {
    flex: 1;
    min-height: 320px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: auto;
}

.purchase-detail-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    min-height: 320px;
}

.purchase-detail-panel__title {
    font-size: 17px;
    font-weight: 700;
    margin: 0 0 8px;
}

.purchase-detail-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 13px;
    text-align: center;
    padding: 24px;
}

.purchase-detail-net {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
    font-weight: 700;
    font-size: 15px;
    color: #0f766e;
}

/* ——— محرّر الفاتورة ——— */
.purchase-editor {
    display: grid;
    grid-template-columns: minmax(130px, 155px) minmax(0, 1fr) minmax(340px, 400px);
    gap: 10px;
    flex: 1;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

.purchase-editor--no-categories {
    grid-template-columns: minmax(0, 1fr) minmax(340px, 400px);
}

.purchase-categories {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    max-height: 100%;
}

.purchase-categories__head {
    background: linear-gradient(180deg, #0f766e, #0d9488);
    color: #fff;
    padding: 14px 12px;
}

.purchase-categories__head h3 {
    margin: 8px 0 0;
    font-size: 14px;
    font-weight: 700;
}

.purchase-categories__sub {
    font-size: 10px;
    color: #ccfbf1;
    margin-top: 4px;
}

.purchase-back-btn {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.purchase-back-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

.purchase-categories__list {
    flex: 1;
    overflow: auto;
    padding: 8px;
}

.purchase-category-chip {
    display: block;
    width: calc(100% - 16px);
    margin: 0 8px 8px;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    color: #334155;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.purchase-category-chip:hover {
    background: #eff6ff;
    border-color: #0d9488;
}

.purchase-category-chip.is-active {
    background: rgba(13, 148, 136, 0.1);
    border-color: #0d9488;
    color: #0f766e;
}

.purchase-catalog {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

.purchase-catalog__top {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
}

.purchase-catalog__toolbar {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 14px;
}

.purchase-catalog__toolbar-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    align-items: center;
}

.purchase-catalog__title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 17px;
    font-weight: 700;
    white-space: nowrap;
}

.purchase-catalog__fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: min(100%, 360px);
    margin-inline-start: auto;
}

.purchase-catalog__field {
    margin: 0;
    min-width: 0;
}

.purchase-catalog__field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 4px;
}

.purchase-catalog__field .search-select__control,
.purchase-catalog__field .purchase-search-box {
    min-height: 40px;
}

.purchase-search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    padding: 0 10px;
    min-height: 40px;
}

.purchase-search-box input {
    border: 0;
    background: transparent;
    flex: 1;
    min-width: 0;
    font-size: 13px;
    outline: none;
}

.purchase-barcode-row {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    min-height: 40px;
}

.purchase-catalog__grid-wrap {
    flex: 1 1 0;
    min-height: 120px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 10px;
}

.purchase-catalog-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 200px;
    padding: 24px 20px;
    gap: 8px;
}

.purchase-catalog-empty__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    border-radius: 18px;
    background: linear-gradient(135deg, #ecfdf5, #f0fdfa);
    color: #0d9488;
    font-size: 28px;
    margin-bottom: 8px;
}

.purchase-catalog-empty--filter .purchase-catalog-empty__icon {
    background: #f8fafc;
    color: #94a3b8;
    font-size: 32px;
    font-weight: 300;
}

.purchase-catalog-empty__title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
}

.purchase-catalog-empty__hint {
    margin: 0;
    max-width: 320px;
    font-size: 13px;
    line-height: 1.6;
    color: #64748b;
}

.purchase-catalog-empty__cta {
    margin-top: 12px;
    min-width: 160px;
}

.purchase-product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 8px;
    align-content: start;
}

.purchase-product-card {
    width: 100%;
    min-height: 148px;
    padding: 12px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    text-align: start;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}

.purchase-product-card:hover {
    border-color: #0d9488;
    box-shadow: 0 8px 20px rgba(13, 148, 136, 0.12);
    transform: translateY(-1px);
}

.purchase-product-card__name {
    font-size: 12px;
    font-weight: 600;
    color: #0f172a;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.purchase-product-card__meta {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 4px;
}

.purchase-product-card__stock {
    font-size: 10px;
    color: #64748b;
    margin-top: 2px;
}

.purchase-product-card__cost {
    margin-top: 8px;
    padding: 6px 8px;
    border-radius: 8px;
    background: #ecfdf5;
    font-size: 11px;
    font-weight: 700;
    color: #0f766e;
}

.purchase-catalog__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-top: 0;
    border-radius: 0 0 12px 12px;
    font-size: 11px;
    color: #64748b;
}

.purchase-cart-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

.purchase-cart-panel__main {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-inline-end: 2px;
}

.purchase-cart-panel__main.purchase-scroll {
    overflow-x: hidden;
    overflow-y: auto;
}

/* كارت فاتورة الشراء + المورد (مدمج) */
.purchase-invoice-card {
    flex-shrink: 0;
    margin-bottom: 0;
    border-radius: 14px;
    overflow: visible;
    border: 1px solid rgba(13, 148, 136, 0.28);
    box-shadow: 0 6px 18px rgba(13, 148, 136, 0.1);
    background: #fff;
}

.purchase-invoice-card__banner {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    background: linear-gradient(135deg, #0f766e 0%, #0d9488 48%, #14b8a6 100%);
    color: #fff;
    border-radius: 13px 13px 0 0;
    overflow: hidden;
}

.purchase-invoice-card__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.purchase-invoice-card__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.22);
}

.purchase-invoice-card__titles {
    min-width: 0;
}

.purchase-invoice-card__titles h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.25;
}

.purchase-invoice-card__titles p {
    margin: 3px 0 0;
    font-size: 10px;
    color: #ccfbf1;
    font-weight: 500;
}

.purchase-invoice-card__date {
    flex-shrink: 0;
    text-align: end;
}

.purchase-invoice-card__date label {
    display: block;
    font-size: 9px;
    font-weight: 600;
    color: #ccfbf1;
    margin-bottom: 3px;
    letter-spacing: 0.02em;
}

.purchase-invoice-card__date-input {
    min-height: 34px;
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.95);
    color: #0f172a;
    width: 132px;
}

.purchase-invoice-card__supplier {
    padding: 8px 10px 10px;
    background: linear-gradient(180deg, #f0fdfa 0%, #fff 100%);
    border-top: 1px solid rgba(13, 148, 136, 0.12);
    border-radius: 0 0 13px 13px;
}

.purchase-invoice-card__supplier label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: #0f766e;
    margin-bottom: 5px;
    letter-spacing: 0.01em;
}

.purchase-invoice-card__supplier label .required {
    color: #ef4444;
}

.purchase-invoice-card__supplier-select .search-select__control,
.purchase-invoice-card__supplier-select .search-select__input {
    min-height: 38px;
    font-size: 12px;
}

.purchase-invoice-card__supplier-select .search-select__control {
    background: #fff;
    border-color: #99f6e4;
}

/* Supplier dropdown — overlay outside invoice card (like category/brand) */
.purchase-invoice-card:has(.search-select.is-open) {
    position: relative;
    z-index: 40;
}

.purchase-invoice-card__supplier:has(.search-select.is-open) {
    position: relative;
    z-index: 50;
}

.purchase-invoice-card__supplier-select.is-open .search-select__panel {
    z-index: 1400;
    box-shadow:
        0 20px 48px rgba(15, 23, 42, 0.18),
        0 0 0 1px rgba(13, 148, 136, 0.08);
}

.purchase-cart-panel__main:has(.search-select.is-open) {
    overflow: visible;
}

.purchase-cart-panel:has(.search-select.is-open) {
    overflow: visible;
    z-index: 25;
}

.purchase-invoice-card:has(.search-select.is-open) ~ .purchase-cart-lines-head,
.purchase-invoice-card:has(.search-select.is-open) ~ .purchase-cart-lines-wrap {
    position: relative;
    z-index: 1;
}

.purchase-cart-lines-head {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 2px 6px;
}

.purchase-cart-lines-head__title {
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    letter-spacing: 0.02em;
}

.purchase-cart-lines-head__count {
    font-size: 10px;
    font-weight: 600;
    color: #0f766e;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(13, 148, 136, 0.1);
}

.purchase-cart-panel__head {
    flex-shrink: 0;
    background: linear-gradient(180deg, #0f766e, #0d9488);
    color: #fff;
    border-radius: 12px;
    padding: 10px 12px;
}

.purchase-cart-panel__head h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
}

.purchase-cart-panel__meta {
    font-size: 11px;
    color: #ccfbf1;
    margin-top: 6px;
}

.purchase-cart-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 10px 0 8px;
    flex-shrink: 0;
}

.purchase-cart-meta-grid label {
    display: block;
    font-size: 11px;
    color: #64748b;
    margin-bottom: 4px;
}

.purchase-cart-lines-wrap {
    flex: 0 0 auto;
    min-height: 96px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fafbfc;
}

.purchase-cart-panel__footer {
    flex-shrink: 0;
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px solid #e2e8f0;
    background: linear-gradient(180deg, #fff 0%, #f8fafc 100%);
    border-radius: 0 0 10px 10px;
    box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.08);
    position: relative;
    z-index: 2;
}

.purchase-cart-panel__alert {
    margin: 0 10px 8px;
    font-size: 12px;
    padding: 8px 10px;
}

.purchase-cart-panel__footer .purchase-net-box__value {
    font-size: 18px;
}

.purchase-cart-lines {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.purchase-cart-lines th {
    position: sticky;
    top: 0;
    background: #f8fafc;
    padding: 10px 8px;
    text-align: center;
    font-weight: 600;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}

.purchase-cart-lines td {
    padding: 8px;
    text-align: center;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.purchase-cart-lines td:first-child {
    text-align: start;
    font-weight: 600;
    max-width: 120px;
    font-size: 11px;
    line-height: 1.35;
}

.purchase-cart-lines .input {
    min-height: 32px;
    padding: 4px 6px;
    text-align: center;
    font-size: 11px;
}

.purchase-line-total {
    font-weight: 700;
    color: #0f766e;
}

.purchase-line-delete {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid #fecaca;
    background: #fff5f5;
    color: #ef4444;
    font-weight: 700;
    cursor: pointer;
}

.purchase-line-delete:hover {
    background: #ef4444;
    color: #fff;
    border-color: #dc2626;
}

.purchase-totals {
    margin-top: 0;
    padding: 10px 10px 8px;
    background: transparent;
    border: 0;
    border-radius: 0;
}

.purchase-totals__row {
    display: grid;
    grid-template-columns: 1.1fr 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}

.purchase-totals__label {
    font-size: 11px;
    color: #64748b;
}

.purchase-totals__value {
    font-size: 14px;
    font-weight: 600;
    color: #0f172a;
    margin-top: 4px;
}

.purchase-net-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-radius: 10px;
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
}

.purchase-net-box__label {
    font-size: 14px;
    font-weight: 600;
    color: #15803d;
}

.purchase-net-box__value {
    font-size: 20px;
    font-weight: 800;
    color: #0f766e;
}

.purchase-cart-actions {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    margin-top: 8px;
    padding: 0 10px;
}

.purchase-btn-clear {
    min-width: 110px;
    min-height: 46px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
}

.purchase-btn-clear:hover {
    background: #f8fafc;
}

.purchase-btn-post {
    min-height: 46px;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(180deg, #16a34a, #15803d);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(22, 163, 74, 0.25);
}

.purchase-btn-post:hover:not(:disabled) {
    filter: brightness(1.05);
}

.purchase-btn-post:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.purchase-btn-draft {
    margin: 8px 10px 10px;
    width: calc(100% - 20px);
    min-height: 40px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    border-radius: 10px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
}

.purchase-mobile-tabs {
    display: none;
    flex-shrink: 0;
}

.purchase-page__body--editor .purchase-mobile-tabs {
    margin-bottom: 8px;
}

@media (max-width: 1100px) {
    .purchase-page--editor {
        --purchase-chrome: 148px;
        height: auto;
        max-height: none;
        overflow: visible;
    }

    .purchase-page__body--editor {
        overflow: visible;
    }

    .purchase-list-layout {
        grid-template-columns: 1fr;
    }

    .purchase-detail-panel {
        min-height: 240px;
    }

    .purchase-editor {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(280px, 42vh) minmax(320px, auto);
        height: auto;
        max-height: none;
        overflow: visible;
    }

    .purchase-editor--no-categories {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(280px, 42vh) minmax(320px, auto);
    }

    .purchase-categories,
    .purchase-catalog,
    .purchase-cart-panel {
        height: auto;
        max-height: none;
    }

    .purchase-cart-panel__footer {
        position: sticky;
        bottom: 0;
        z-index: 2;
    }

    .purchase-categories__list {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 8px;
        gap: 8px;
    }

    .purchase-category-chip {
        width: auto;
        min-width: 100px;
        margin: 0;
        flex-shrink: 0;
    }

    .purchase-mobile-tabs {
        display: flex;
        gap: 8px;
        margin-bottom: 8px;
    }

    .purchase-mobile-tab {
        flex: 1;
        padding: 10px;
        border-radius: 10px;
        border: 1px solid #e2e8f0;
        background: #fff;
        font-weight: 600;
        font-size: 13px;
        cursor: pointer;
    }

    .purchase-mobile-tab.is-active {
        background: rgba(13, 148, 136, 0.12);
        border-color: #0d9488;
        color: #0f766e;
    }

    .purchase-editor-pane.is-hidden-mobile {
        display: none;
    }

    .purchase-catalog__toolbar-grid {
        grid-template-columns: 1fr;
    }

    .purchase-catalog__fields {
        grid-template-columns: 1fr 1fr;
        width: 100%;
        margin-inline-start: 0;
    }

    .purchase-invoice-card__banner {
        flex-wrap: wrap;
    }

    .purchase-invoice-card__date {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }

    .purchase-invoice-card__date-input {
        flex: 1;
        max-width: 180px;
    }
}
