:root {
    --sp-bg: #f4f7fb;
    --sp-card: #ffffff;
    --sp-text: #0f172a;
    --sp-muted: #64748b;
    --sp-line: #e2e8f0;
    --sp-head: #114d78;
    --sp-head-2: #0b3d62;
    --sp-primary: #2563eb;
    --sp-primary-soft: #eff6ff;
    --sp-shadow: 0 12px 30px rgba(2, 16, 32, .06);
    --sp-radius: 18px;
}

.page-wrapper.fade-in {
    background: linear-gradient(180deg, #f8fbff 0%, #f4f7fb 100%);
    padding: 14px;
    border-radius: 22px;
}

.stock-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.stock-title {
    margin: 0;
    font-size: 28px;
    font-weight: 900;
    color: var(--sp-text);
}

.stock-subtitle {
    color: var(--sp-muted);
    font-size: 13px;
    margin-top: 4px;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.summary-cards .card {
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    border: 1px solid var(--sp-line);
    border-radius: 20px;
    box-shadow: var(--sp-shadow);
    padding: 16px;
}

.summary-cards .card h4 {
    margin: 0 0 8px;
    font-size: 13px;
    color: var(--sp-muted);
    font-weight: 800;
}

.summary-cards .card p {
    margin: 0;
    font-size: 30px;
    font-weight: 900;
    color: var(--sp-text);
}

.stock-filter-card,
.stock-table-card {
    background: var(--sp-card);
    border: 1px solid var(--sp-line);
    border-radius: 22px;
    box-shadow: var(--sp-shadow);
}

.stock-filter-card {
    padding: 16px;
    margin-bottom: 16px;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 14px;
    align-items: end;
}

.filter-col label {
    display: block;
    margin-bottom: 6px;
    color: var(--sp-muted);
    font-weight: 800;
    font-size: 12px;
}

.form-control {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid var(--sp-line);
    background: #fff;
    color: var(--sp-text);
    transition: .2s ease;
    font: inherit;
}

.form-control:focus {
    outline: none;
    border-color: #93c5fd;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}

.btn-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    min-height: 46px;
    padding: 10px 14px;
    border-radius: 14px;
    border: none;
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    cursor: pointer;
    transition: .2s ease;
}

.btn.primary {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
}

.btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(37, 99, 235, .25);
}

.btn.secondary {
    background: #f8fafc;
    color: #0f172a;
    border: 1px solid var(--sp-line);
}

.btn.secondary:hover {
    background: #f1f5f9;
}

.stock-table-card {
    padding: 12px;
}

.table-scroll {
    overflow: auto;
    border-radius: 18px;
}

.table-basic {
    width: 100%;
    min-width: 880px;
    border-collapse: separate;
    border-spacing: 0;
}

.table-basic thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: linear-gradient(180deg, var(--sp-head), var(--sp-head-2));
    color: #fff;
    padding: 14px 12px;
    font-size: 13px;
    font-weight: 900;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.table-basic thead th:first-child {
    border-top-right-radius: 16px;
}

.table-basic thead th:last-child {
    border-top-left-radius: 16px;
}

.table-basic tbody td {
    background: #fff;
    padding: 12px;
    border-bottom: 1px solid #edf2f7;
    vertical-align: middle;
}

.table-basic tbody tr.product-row:hover td {
    background: #fbfdff;
}

.table-basic code {
    background: #f8fafc;
    border: 1px solid var(--sp-line);
    border-radius: 10px;
    padding: 3px 8px;
    font-size: 12px;
}

.toggle-ledger {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #f8fafc;
    border: 1px solid var(--sp-line);
    transition: .2s ease;
}

.toggle-ledger:hover {
    background: #eef2ff;
    border-color: #c7d2fe;
}

.toggle-ledger .arrow {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 8px solid #0b4f6c;
    transition: transform .25s ease;
}

.toggle-ledger.open .arrow {
    transform: rotate(180deg);
}

.btn-action {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 900;
    transition: .2s ease;
}

.btn-action.purple {
    background: #eef2ff;
    color: #4338ca;
    border: 1px solid #c7d2fe;
}

.btn-action.purple:hover {
    background: #e0e7ff;
    transform: translateY(-1px);
}

.ledger-row td {
    background: #fbfdff !important;
    padding: 0 12px 14px !important;
}

.ledger-box {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height .35s ease, opacity .2s ease, padding .2s ease;
    padding: 0;
}

.ledger-box.open {
    max-height: 1600px;
    opacity: 1;
    padding: 12px 0 0;
}

.ledger-status {
    margin-top: 10px;
}

.ledger-loader,
.ledger-end,
.ledger-empty,
.ledger-error {
    padding: 10px 12px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 13px;
    text-align: center;
}

.ledger-loader {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px dashed #93c5fd;
}

.ledger-end,
.ledger-empty {
    background: #f8fafc;
    color: #64748b;
    border: 1px dashed #cbd5e1;
}

.ledger-error {
    background: #fff1f2;
    color: #9f1239;
    border: 1px dashed #fda4af;
}

.scroll-sentinel {
    height: 8px;
}

/* ===== Adjust Modal ===== */
/* النافذة تتحرك مع سكرول الصفحة الرئيسي */
/* ===== Adjust Modal ===== */
/* ===== Adjust Modal ===== */
.bs-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, .45);
    backdrop-filter: blur(6px);
    overflow-y: auto;
    overflow-x: hidden;
}

.bs-sheet {
    width: min(640px, calc(100vw - 32px));
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    overflow-x: hidden;
    margin: auto;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    box-shadow: 0 24px 70px rgba(2, 16, 32, .18);
    padding: 18px;
    box-sizing: border-box;
}

.bs-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid #edf2f7;
}

.bs-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.bs-title {
    margin: 0;
    font-size: 20px;
    font-weight: 900;
    color: #0f172a;
    line-height: 1.35;
}

.bs-subtitle {
    color: #64748b;
    font-size: 12px;
    line-height: 1.5;
    font-weight: 700;
}

.bs-close {
    width: 38px;
    height: 38px;
    border: 1px solid #dbe2ea;
    background: #fff;
    color: #334155;
    border-radius: 12px;
    cursor: pointer;
    font-size: 20px;
    font-weight: 900;
    flex: 0 0 auto;
    transition: .2s ease;
}

.bs-close:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.adjust-top {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.adjust-stat {
    background: linear-gradient(180deg, #ffffff, #f8fbff);
    border: 1px solid #dbe7f3;
    border-radius: 16px;
    padding: 12px 14px;
    min-height: 82px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.adjust-stat .k {
    font-size: 11px;
    font-weight: 800;
    color: #64748b;
    margin-bottom: 5px;
}

.adjust-stat .v {
    font-size: 22px;
    font-weight: 900;
    color: #0f172a;
    line-height: 1.15;
}

.adjust-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: start;
}

.bs-row {
    margin: 0;
    min-width: 0;
}

.bs-row.full {
    grid-column: 1 / -1;
}

.bs-row label {
    display: block;
    margin-bottom: 6px;
    color: #475569;
    font-size: 12px;
    font-weight: 800;
}

.bs-row input,
.bs-row textarea,
.bs-static {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid #dbe2ea;
    background: #fff;
    color: #0f172a;
    font: inherit;
    font-size: 14px;
    box-sizing: border-box;
}

.bs-row textarea {
    min-height: 96px;
    resize: vertical;
}

.bs-row input:focus,
.bs-row textarea:focus {
    outline: none;
    border-color: #93c5fd;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}

.bs-row input[disabled] {
    background: #f8fafc;
    color: #475569;
    font-weight: 800;
}

.bs-static {
    display: flex;
    align-items: center;
    font-weight: 900;
    background: #f8fafc;
}

.bs-static.muted {
    color: #0f172a;
}

.bs-static.pos {
    color: #059669;
    background: #ecfdf5;
    border-color: #bbf7d0;
}

.bs-static.neg {
    color: #dc2626;
    background: #fef2f2;
    border-color: #fecaca;
}

.bs-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #edf2f7;
    background: #fff;
}

.bs-actions .btn {
    min-width: 118px;
    min-height: 42px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 900;
}

.bs-actions .btn.primary {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    border: none;
    box-shadow: 0 10px 24px rgba(37, 99, 235, .22);
}

.bs-actions .btn.secondary {
    background: #fff;
    color: #334155;
    border: 1px solid #dbe2ea;
}

.bs-actions .btn:hover {
    transform: translateY(-1px);
}

@media (max-width: 1366px) {
    .bs-overlay {
        padding: 16px;
    }

    .bs-sheet {
        width: min(560px, calc(100vw - 24px));
        max-height: calc(100vh - 24px);
        padding: 14px;
        border-radius: 16px;
    }

    .bs-head {
        margin-bottom: 10px;
        padding-bottom: 8px;
    }

    .bs-title {
        font-size: 18px;
        line-height: 1.25;
    }

    .bs-subtitle {
        font-size: 11px;
        line-height: 1.35;
    }

    .adjust-top {
        gap: 8px;
        margin-bottom: 10px;
    }

    .adjust-stat {
        min-height: 64px;
        padding: 9px 10px;
        border-radius: 12px;
    }

    .adjust-stat .k {
        font-size: 10px;
        margin-bottom: 2px;
    }

    .adjust-stat .v {
        font-size: 16px;
    }

    .adjust-grid {
        gap: 8px 10px;
    }

    .bs-row label {
        margin-bottom: 4px;
        font-size: 11px;
    }

    .bs-row input,
    .bs-row textarea,
    .bs-static {
        min-height: 38px;
        padding: 8px 10px;
        font-size: 12px;
        border-radius: 10px;
    }

    .bs-row textarea {
        min-height: 78px;
    }

    .bs-actions {
        margin-top: 12px;
        padding-top: 10px;
        gap: 6px;
    }

    .bs-actions .btn {
        min-width: 100px;
        min-height: 36px;
        font-size: 12px;
        border-radius: 10px;
    }
}

@media (max-width: 768px) {
    .bs-overlay {
        align-items: flex-start;
        padding: 10px;
    }

    .bs-sheet {
        width: 100%;
        max-height: calc(100vh - 20px);
        margin: 0 auto;
        border-radius: 16px;
    }

    .adjust-top,
    .adjust-grid {
        grid-template-columns: 1fr;
    }

    .bs-actions {
        position: sticky;
        bottom: 0;
        flex-direction: column-reverse;
    }

    .bs-actions .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .summary-cards {
        grid-template-columns: 1fr;
    }

    .table-basic {
        min-width: 680px;
    }

    .toggle-ledger,
    .btn-action {
        width: 34px;
        height: 34px;
    }

    .bs-overlay {
        padding: 8px;
    }

    .bs-sheet {
        max-height: calc(100vh - 16px);
        padding: 12px;
        border-radius: 14px;
    }

    .bs-title {
        font-size: 16px;
    }

    .bs-close {
        width: 34px;
        height: 34px;
        font-size: 18px;
        border-radius: 10px;
    }
}

@media (max-width: 480px) {
    .summary-cards {
        grid-template-columns: 1fr;
    }

    .table-basic {
        min-width: 680px;
    }

    .toggle-ledger,
    .btn-action {
        width: 34px;
        height: 34px;
    }
}

/* ===== Custom UI Messages ===== */
.ui-message-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, .45);
    backdrop-filter: blur(4px);
}

.ui-message-box {
    width: min(420px, calc(100vw - 32px));
    background: #fff;
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 24px 70px rgba(2, 16, 32, .20);
    padding: 18px;
    animation: uiMessageIn .18s ease;
    text-align: right;
}

@keyframes uiMessageIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ui-message-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 900;
    margin-bottom: 12px;
    background: #fff7ed;
    color: #ea580c;
    border: 1px solid #fed7aa;
}

.ui-message-box.success .ui-message-icon {
    background: #ecfdf5;
    color: #059669;
    border-color: #bbf7d0;
}

.ui-message-box.error .ui-message-icon {
    background: #fef2f2;
    color: #dc2626;
    border-color: #fecaca;
}

.ui-message-box.info .ui-message-icon {
    background: #eff6ff;
    color: #2563eb;
    border-color: #bfdbfe;
}

.ui-message-title {
    margin: 0 0 6px;
    font-size: 18px;
    font-weight: 900;
    color: #0f172a;
}

.ui-message-text {
    color: #475569;
    font-size: 14px;
    line-height: 1.8;
    font-weight: 700;
}

.ui-message-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.ui-message-btn {
    min-width: 110px;
    min-height: 42px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    font-size: 14px;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(37, 99, 235, .22);
}

.ui-message-btn:hover {
    transform: translateY(-1px);
}

@media (max-width: 480px) {
    .ui-message-box {
        padding: 14px;
        border-radius: 14px;
    }

    .ui-message-title {
        font-size: 16px;
    }

    .ui-message-text {
        font-size: 13px;
    }

    .ui-message-btn {
        width: 100%;
    }

    .ui-message-actions {
        justify-content: stretch;
    }
}