:root {
    --bg: #edf2f4;
    --panel: #ffffff;
    --ink: #15202b;
    --muted: #5c6c7c;
    --line: #dce3eb;
    --brand: #1f6feb;
    --brand-dark: #164fa8;
    --accent: #13b0a5;
    --sidebar-bg: linear-gradient(185deg, #0f1f33 0%, #132b46 45%, #16395a 100%);
    --sidebar-ink: #d6e4f5;
}

* {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

body.app-body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 5% 0%, rgba(31, 111, 235, 0.12), transparent 40%),
        radial-gradient(circle at 95% 15%, rgba(19, 176, 165, 0.1), transparent 45%),
        var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", "Trebuchet MS", "Verdana", sans-serif;
}

.app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 1030;
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
    color: var(--sidebar-ink);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04), 0 14px 40px rgba(10, 18, 30, 0.36);
}

.sidebar-head {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 1rem;
    border-bottom: 1px solid rgba(214, 228, 245, 0.12);
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(145deg, var(--brand), var(--accent));
}

.brand-title {
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.1;
}

.brand-meta {
    font-size: 0.76rem;
    color: rgba(214, 228, 245, 0.72);
}

.sidebar-scroll {
    overflow-y: auto;
    padding: 0.75rem;
}

.nav-section {
    margin-bottom: 0.9rem;
}

.nav-caption {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(214, 228, 245, 0.58);
    margin: 0.35rem 0.55rem;
}

.nav-pill {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.65rem;
    margin: 0.15rem 0;
    border-radius: 10px;
    color: var(--sidebar-ink);
    text-decoration: none;
    transition: background-color 0.2s ease, transform 0.2s ease, color 0.2s ease;
}

.nav-pill:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    transform: translateX(2px);
}

.nav-pill.is-active {
    background: rgba(31, 111, 235, 0.35);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.nav-icon {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.nav-icon svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar-foot {
    margin-top: auto;
    padding: 0.75rem;
    border-top: 1px solid rgba(214, 228, 245, 0.12);
}

.app-main {
    margin-left: 280px;
    padding: 1.25rem;
}

.demo-upgrade-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 0.9rem 1rem;
    border: 1px solid rgba(25, 135, 84, 0.28);
    border-left: 4px solid #198754;
    border-radius: 8px;
    background: #f1fbf6;
    color: #123524;
    box-shadow: 0 8px 24px rgba(16, 24, 32, 0.05);
}

.demo-upgrade-bar strong {
    display: block;
    line-height: 1.2;
}

.demo-upgrade-bar span {
    color: #4d6358;
    font-size: 0.92rem;
}

.demo-upgrade-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
}

.demo-upgrade-bar form {
    margin: 0;
}

.mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 1025;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 0.9rem;
    background: rgba(15, 31, 51, 0.95);
    color: #f0f6ff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    gap: 0.6rem;
}

.mobile-brand {
    font-weight: 700;
    font-size: 0.92rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.platform-shell {
    max-width: 1680px;
    margin: 0 auto;
}

.platform-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.lead-followup-cell {
    min-width: 230px;
}

main .card,
main .table,
main .alert,
main .form-control,
main .form-select,
main .modal-content,
main .list-group-item,
main .accordion-item {
    border-color: var(--line);
}

main .card,
main .table,
main .modal-content {
    box-shadow: 0 8px 24px rgba(16, 24, 32, 0.05);
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.stat-card {
    border: 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.stat-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.stat-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card .stat-label {
    color: #6c757d;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-card .stat-value {
    font-size: 1.8rem;
    font-weight: 700;
}

.stat-card.warn {
    border-left: 4px solid #ffc107;
}

.stat-card.danger {
    border-left: 4px solid #dc3545;
}

.items-table {
    min-width: 620px;
}

.barcode-copy-input {
    width: 84px;
}

.barcode-scan-panel {
    max-width: 520px;
    background: #f7fbff;
}

.barcode-sheet {
    display: grid;
    grid-template-columns: repeat(auto-fill, var(--label-width));
    gap: 2mm;
    align-items: start;
}

.barcode-label {
    width: var(--label-width);
    height: var(--label-height);
    box-sizing: border-box;
    overflow: hidden;
    padding: 2mm;
    border: 1px dashed var(--line);
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    color: #000;
}

.barcode-medicine {
    font-size: 9pt;
    line-height: 1.1;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.barcode-image {
    min-height: 10mm;
    flex: 1;
    display: flex;
    align-items: center;
}

.barcode-svg {
    display: block;
    width: 100%;
    max-height: 14mm;
}

.barcode-value {
    text-align: center;
    font: 8pt "Courier New", monospace;
    letter-spacing: 0.05em;
}

.barcode-meta {
    display: flex;
    justify-content: space-between;
    gap: 2mm;
    font-size: 7pt;
    line-height: 1;
}

.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid #52677f;
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(15, 31, 51, 0.12);
    cursor: pointer;
}

.form-check-input:checked {
    background-color: var(--brand);
    border-color: var(--brand);
}

.form-check-input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 0.2rem rgba(31, 111, 235, 0.22);
}

#poReceiveTable .form-check-input,
#poReceiveTable td > input[type="checkbox"] {
    width: 1.35rem;
    height: 1.35rem;
    margin: 0;
}

#poReceiveTable th:first-child,
#poReceiveTable td:first-child {
    text-align: center;
    vertical-align: middle;
}

.po-receive-table {
    min-width: 1180px;
    table-layout: fixed;
}

.po-receive-table th,
.po-receive-table td {
    vertical-align: middle;
}

.po-receive-table .po-receive-check {
    width: 90px;
}

.po-receive-table .po-receive-medicine {
    width: 260px;
}

.po-receive-table .po-receive-small {
    width: 92px;
}

.po-receive-table .po-receive-qty {
    width: 130px;
}

.po-receive-table .po-receive-batch {
    width: 130px;
}

.po-receive-table .po-receive-date {
    width: 170px;
}

.po-receive-table .po-receive-cost {
    width: 130px;
}

.po-receive-table .po-receive-price {
    width: 160px;
}

.po-receive-table .form-control {
    min-width: 0;
}

@media (max-width: 991.98px) {
    .app-main {
        margin-left: 0;
        padding: 0.8rem;
    }

    .offcanvas.offcanvas-start {
        width: min(86vw, 320px);
    }
}

@media (max-width: 768px) {
    body.app-body {
        background:
            linear-gradient(145deg, rgba(31, 111, 235, 0.08), rgba(19, 176, 165, 0.08)),
            var(--bg);
    }

    .app-main {
        padding: 0.7rem;
    }

    .app-main h1,
    .app-main h2 {
        font-size: 1.55rem;
        line-height: 1.2;
    }

    .app-main > .d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .demo-upgrade-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .demo-upgrade-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .demo-upgrade-bar .btn {
        width: 100%;
    }

    main .card {
        border-radius: 12px;
    }

    main .card.p-3 {
        padding: 0.85rem !important;
    }

    .btn {
        min-height: 38px;
    }

    .stat-card .stat-value {
        font-size: 1.45rem;
    }

    .table {
        min-width: 640px;
        margin-bottom: 0;
    }

    .table th,
    .table td {
        white-space: nowrap;
        padding: 0.55rem 0.65rem;
    }

    .table:not(.table-sm) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 576px) {
    .app-main {
        padding: 0.6rem;
    }

    .mobile-topbar {
        padding: 0.55rem 0.65rem;
    }

    .mobile-topbar .btn {
        padding: 0.35rem 0.55rem;
        font-size: 0.82rem;
    }

    .app-main > .d-flex {
        align-items: stretch !important;
    }

    .app-main > .d-flex > .btn,
    .app-main > .d-flex > div > .btn {
        width: 100%;
    }

    .app-main > .d-flex > div {
        width: 100%;
    }

    .app-main > .d-flex > div.d-flex {
        flex-wrap: wrap;
    }

    form.card .row > [class*="col-"] {
        margin-bottom: 0.15rem;
    }

    form.card .btn {
        width: 100%;
    }

    .form-control,
    .form-select,
    .btn {
        font-size: 0.95rem;
    }

    .alert {
        padding: 0.75rem;
        font-size: 0.92rem;
    }

    .table {
        min-width: 560px;
        font-size: 0.88rem;
    }

    .items-table-wrap {
        overflow-x: auto;
    }

    .items-table th,
    .items-table td {
        white-space: nowrap;
        padding: 6px 8px;
        font-size: 0.85rem;
    }

    .items-table .form-control,
    .items-table .form-select {
        min-width: 90px;
        height: 34px;
        font-size: 0.85rem;
    }

    .items-table .qty-input,
    .items-table .price-input {
        min-width: 70px;
    }
}

@media print {
    @page {
        margin: 6mm;
    }

    body.app-body {
        background: #fff !important;
    }

    .app-sidebar,
    .mobile-topbar,
    .offcanvas,
    .print-hide {
        display: none !important;
    }

    .app-main {
        margin: 0 !important;
        padding: 0 !important;
    }

    .barcode-sheet {
        gap: 0;
    }

    .barcode-label {
        border: 0;
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
