/* =====================================================================
 * Nasima Pharma ERP — রেসপন্সিভ + মোবাইল অ্যাপ স্তর (np-responsive.css)
 * header.php থেকে লোড হয়। শুধু চেহারা/লেআউট — কোনো কুয়েরি, সূত্র বা সংখ্যা ছোঁয় না।
 * ব্রেকপয়েন্ট: ≤991px = ট্যাবলেট/মোবাইল (সাইডবার ড্রয়ার), ≤575px = ফোন (টেবিল কার্ড)।
 * ===================================================================== */

:root {
    --np-r-primary: #0277bd;
    --np-r-primary-soft: #e3f2fd;
    --np-r-surface: #fff;
    --np-r-border: #e3e8ee;
    --np-r-text: #1f2a37;
    --np-r-muted: #6b7785;
    --np-r-radius: 12px;
    --np-r-shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --np-r-shadow-lg: 0 10px 30px rgba(16, 24, 40, .18);
    --np-safe-top: env(safe-area-inset-top, 0px);
    --np-safe-bottom: env(safe-area-inset-bottom, 0px);
    --np-bottomnav-h: 62px;
}

/* ---------- সাধারণ ভিত্তি ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: rgba(2, 119, 189, .12); color: var(--np-r-text); }
img, svg, video, canvas { max-width: 100%; }
button, .btn, a, select, input[type=checkbox], input[type=radio], label { touch-action: manipulation; }
.main-content { min-width: 0; }
.main-content > * { min-width: 0; }

/* ---------- ডিজাইন আপগ্রেড (সব স্ক্রিনে) ---------- */
.top-bar { border-radius: var(--np-r-radius); box-shadow: var(--np-r-shadow); gap: 10px; }
.top-bar h4 { font-size: 1.05rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sidebar a.np-active { background: rgba(255, 255, 255, .18); border-left: 4px solid #ff9f43; font-weight: 600; }
.dropdown-container a.np-active { color: #fff; }
.main-content .card { border-radius: var(--np-r-radius); border-color: var(--np-r-border); box-shadow: var(--np-r-shadow); }
.main-content .card-header { border-top-left-radius: var(--np-r-radius) !important; border-top-right-radius: var(--np-r-radius) !important; }
.main-content .btn { border-radius: 8px; }
.main-content .form-control, .main-content .form-select { border-radius: 8px; }
.main-content .form-control:focus, .main-content .form-select:focus {
    border-color: var(--np-r-primary); box-shadow: 0 0 0 .2rem rgba(2, 119, 189, .15);
}
.main-content .table > thead > tr > th { white-space: nowrap; }
.main-content .badge { font-weight: 600; }
.main-content .modal-content { border-radius: var(--np-r-radius); border: 0; box-shadow: var(--np-r-shadow-lg); }
.table-responsive { -webkit-overflow-scrolling: touch; }
.np-table-wrap { position: relative; }
.pagination { flex-wrap: wrap; }
.nav-tabs, .nav-pills { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; white-space: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.nav-tabs::-webkit-scrollbar, .nav-pills::-webkit-scrollbar { display: none; }
.main-content .modal-footer { flex-wrap: wrap; gap: 6px; }

/* ---------- মোবাইল-ইউআই উপাদান (ডেস্কটপে লুকানো) ---------- */
.np-menu-btn, .np-back-btn {
    display: none; align-items: center; justify-content: center; flex: 0 0 auto;
    width: 42px; height: 42px; border: 0; border-radius: 12px;
    background: var(--np-r-primary-soft); color: var(--np-r-primary); font-size: 18px; cursor: pointer;
}
.np-menu-btn:active, .np-back-btn:active { background: #cfe8fb; }
.np-overlay { display: none; }
.np-bottomnav { display: none; }
.np-sidebar-close { display: none; }
.np-install-top { display: none; }
.np-top-right { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; min-width: 0; }
.np-top-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.np-install-menu { display: none; }
.np-install-menu.np-show { display: block; }
html.np-standalone .np-back-btn { display: inline-flex; }

/* ---------- ইনস্টল ব্যানার (সব স্ক্রিনে) ---------- */
.np-install {
    position: fixed; left: 50%; bottom: calc(14px + var(--np-safe-bottom)); transform: translate(-50%, 140%);
    width: min(440px, calc(100vw - 20px)); z-index: 2000; background: #fff; color: var(--np-r-text);
    border-radius: 16px; box-shadow: var(--np-r-shadow-lg); border: 1px solid var(--np-r-border);
    padding: 14px; display: flex; gap: 12px; align-items: flex-start;
    transition: transform .35s cubic-bezier(.2, .8, .2, 1);
}
.np-install.np-open { transform: translate(-50%, 0); }
.np-install img { width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--np-r-border); flex: 0 0 auto; }
.np-install .np-i-body { flex: 1 1 auto; min-width: 0; }
.np-install .np-i-title { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.np-install .np-i-text { font-size: 13px; color: var(--np-r-muted); line-height: 1.45; }
.np-install .np-i-actions { display: flex; gap: 8px; margin-top: 10px; }
.np-install .np-i-actions button { flex: 1; border: 0; border-radius: 10px; padding: 10px 12px; font-weight: 600; font-size: 14px; cursor: pointer; }
.np-install .np-i-yes { background: var(--np-r-primary); color: #fff; }
.np-install .np-i-no { background: #eef1f5; color: #46515f; }
.np-install .np-i-steps { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: #394452; line-height: 1.6; }
.np-install .np-i-x { position: absolute; top: 6px; right: 8px; border: 0; background: none; font-size: 20px; color: #94a0ad; cursor: pointer; line-height: 1; padding: 4px 8px; }
@media (max-width: 991.98px) {
    .np-install { bottom: calc(var(--np-bottomnav-h) + 12px + var(--np-safe-bottom)); }
}

/* =====================================================================
 * ট্যাবলেট ও মোবাইল (≤991px): সাইডবার = ড্রয়ার, উপরে অ্যাপ-বার, নিচে নেভিগেশন
 * ===================================================================== */
@media (max-width: 991.98px) {
    body { overflow-x: hidden; padding-bottom: calc(var(--np-bottomnav-h) + var(--np-safe-bottom)); }

    .sidebar {
        width: min(300px, 86vw); height: 100vh; height: 100dvh;
        transform: translateX(-102%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
        z-index: 1050; box-shadow: none; padding-bottom: var(--np-safe-bottom);
        visibility: hidden;
    }
    body.np-menu-open .sidebar { transform: translateX(0); box-shadow: 8px 0 30px rgba(0, 0, 0, .35); visibility: visible; }
    .sidebar .brand { position: sticky; top: 0; z-index: 2; padding-top: calc(16px + var(--np-safe-top)); background: #0a7fb8; }
    .sidebar a, .dropdown-btn { padding: 14px 20px; font-size: 15px; }
    .dropdown-container a { padding: 12px 20px 12px 38px; }
    .sidebar a:hover, .dropdown-btn:hover { padding-left: 20px; }
    .dropdown-container a:hover { padding-left: 38px; }
    .np-sidebar-close {
        display: inline-flex; position: absolute; right: 10px; top: calc(10px + var(--np-safe-top));
        width: 36px; height: 36px; align-items: center; justify-content: center;
        border: 0; border-radius: 10px; background: rgba(255, 255, 255, .18); color: #fff; font-size: 16px;
    }
    .np-overlay {
        display: block; position: fixed; inset: 0; z-index: 1040; background: rgba(10, 20, 30, .5);
        opacity: 0; pointer-events: none; transition: opacity .25s;
    }
    body.np-menu-open .np-overlay { opacity: 1; pointer-events: auto; }
    body.np-menu-open { overflow: hidden; }

    .main-content { margin-left: 0 !important; padding: 0 12px 16px; }
    .top-bar {
        position: sticky; top: 0; z-index: 900; margin: 0 -12px 14px; border-radius: 0;
        padding: calc(8px + var(--np-safe-top)) 12px 8px; box-shadow: 0 1px 0 var(--np-r-border), 0 4px 12px rgba(16, 24, 40, .05);
    }
    .np-menu-btn { display: inline-flex; }
    .top-bar h4 { font-size: 1rem; }
    .np-user-name { display: none; }
    .np-install-top.np-show { display: inline-flex; }

    /* নিচের নেভিগেশন (অ্যাপের মতো) */
    .np-bottomnav {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 950;
        height: calc(var(--np-bottomnav-h) + var(--np-safe-bottom)); padding-bottom: var(--np-safe-bottom);
        background: #fff; border-top: 1px solid var(--np-r-border); box-shadow: 0 -4px 16px rgba(16, 24, 40, .07);
    }
    .np-bottomnav a, .np-bottomnav button {
        flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        border: 0; background: none; color: var(--np-r-muted); text-decoration: none; font-size: 11px; font-weight: 600; padding: 6px 2px;
    }
    .np-bottomnav i { font-size: 19px; }
    .np-bottomnav .np-on { color: var(--np-r-primary); }
    .np-bottomnav .np-pos {
        flex: 0 0 64px; margin-top: -18px; height: 64px; border-radius: 50%; background: #dc3545; color: #fff;
        box-shadow: 0 6px 16px rgba(220, 53, 69, .4); font-size: 11px; align-self: flex-start;
    }
    .np-bottomnav .np-pos i { font-size: 20px; }

    /* ফর্ম-সহায়ক: ১৬px = iOS জুম বন্ধ; বড় টাচ এরিয়া */
    .main-content .form-control, .main-content .form-select, .main-content input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]),
    .main-content select, .main-content textarea { font-size: 16px; min-height: 44px; max-width: 100%; }
    .main-content .form-control-sm, .main-content .form-select-sm { min-height: 40px; font-size: 15px; }
    .main-content .btn { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
    .main-content .btn-sm { min-height: 38px; padding: .35rem .7rem; }
    .main-content .form-check-input { width: 1.25em; height: 1.25em; }
    .main-content .form-label { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
    .main-content .input-group > .form-control, .main-content .input-group > .form-select { min-width: 0; }

    /* ফিল্টার/টুলবার: নিচে নামিয়ে ভাঙো */
    .main-content .d-flex.justify-content-between { flex-wrap: wrap; gap: 8px; }
    /* পেজ-হেডার/ফিল্টার বার: ভেঙে নিচে নামবে, বাইরে উপচাবে না */
    .main-content .page-header, .main-content .np-page-header { flex-wrap: wrap; gap: 10px; }
    .main-content .page-header > *, .main-content .np-page-header > * { min-width: 0; max-width: 100%; }
    .main-content .page-header .d-flex, .main-content .page-header form, .main-content .np-page-header .d-flex { flex-wrap: wrap; gap: 8px; }
    .main-content .page-header select, .main-content .page-header .filter-select { max-width: 100%; }
    .main-content .page-header .ms-2 { margin-left: 0 !important; }
    .main-content h1, .main-content h2 { font-size: 1.4rem; }
    .main-content h3 { font-size: 1.2rem; }
    .main-content h4 { font-size: 1.1rem; }
    .main-content h5 { font-size: 1rem; }
    .main-content .card-body { padding: 12px; }
    .main-content .card-header { padding: 10px 12px; }
    .main-content .container, .main-content .container-fluid { padding-left: 0; padding-right: 0; }
    .main-content .row { --bs-gutter-x: 0.9rem; }
    .main-content .table-responsive { border-radius: 10px; }
    .main-content .table { font-size: 13px; }
    .main-content .table > :not(caption) > * > * { padding: .5rem .55rem; }
    .main-content [style*="position: fixed"], .main-content [style*="position:fixed"] { max-width: 100vw; }

    /* বড় মডাল: প্রায় ফুলস্ক্রিন */
    .modal-dialog { margin: .6rem; max-width: calc(100vw - 1.2rem); }
    .modal-dialog.modal-lg, .modal-dialog.modal-xl { max-width: calc(100vw - 1.2rem); }
    .modal-dialog-scrollable .modal-content { max-height: calc(100dvh - 1.2rem); }
    .modal-body { overflow-x: auto; }
    footer { padding-bottom: 8px; }
}

/* =====================================================================
 * ফোন (≤575px)
 * ===================================================================== */
@media (max-width: 575.98px) {
    .main-content { padding: 0 10px 14px; }
    .top-bar { margin: 0 -10px 12px; padding-left: 10px; padding-right: 10px; }
    .np-top-title-sub { display: none; }
    .np-pos-top .np-pos-text { display: none; }
    .main-content .btn-group { flex-wrap: wrap; }
    .main-content .page-header select, .main-content .page-header .filter-select { width: 100% !important; }
    .main-content .page-header > div, .main-content .page-header > a { width: 100%; }
    .main-content .page-header .btn, .main-content .page-header .btn-custom { width: 100%; justify-content: center; text-align: center; }
    .main-content .d-flex.gap-2:not(.np-keep), .main-content .btn-toolbar { flex-wrap: wrap; }
    .main-content .col-sm-auto, .main-content .col-auto { max-width: 100%; }
    .main-content .modal-footer .btn { flex: 1 1 auto; }
    .main-content .card .btn.w-sm-auto { width: 100%; }

    /* টেবিল → কার্ড (JS শুধু সহজ লিস্ট-টেবিলে np-stack ক্লাস বসায়) */
    table.np-stack, table.np-stack > tbody, table.np-stack > tfoot, table.np-stack > tbody > tr, table.np-stack > tfoot > tr,
    table.np-stack > tbody > tr > td, table.np-stack > tfoot > tr > td, table.np-stack > tbody > tr > th { display: block; width: 100% !important; }
    table.np-stack > thead { display: none; }
    table.np-stack { border: 0; background: transparent; width: 100% !important; min-width: 0 !important; table-layout: auto; }
    table.np-stack > tbody > tr, table.np-stack > tfoot > tr {
        background: #fff; border: 1px solid var(--np-r-border); border-radius: 12px; margin-bottom: 10px;
        padding: 4px 12px; box-shadow: var(--np-r-shadow);
    }
    table.np-stack > :not(caption) > * > * { box-shadow: none !important; background: transparent !important; }
    table.np-stack > tbody > tr > td, table.np-stack > tbody > tr > th {
        display: flex; justify-content: space-between; align-items: center; gap: 14px; text-align: right !important;
        border: 0; border-bottom: 1px dashed #e7ebf0; padding: 8px 0; min-height: 36px; word-break: break-word;
    }
    table.np-stack > tbody > tr > td:last-child { border-bottom: 0; }
    table.np-stack > tbody > tr > td::before {
        content: attr(data-label); flex: 0 0 38%; max-width: 45%; text-align: left; font-weight: 600; font-size: 12px; color: var(--np-r-muted);
    }
    table.np-stack > tbody > tr > td[data-label=""]::before { display: none; }
    table.np-stack > tbody > tr > td[data-label=""] { justify-content: flex-end; flex-wrap: wrap; }
    table.np-stack > tbody > tr > td { flex-wrap: wrap; }
    table.np-stack > tbody > tr > td > * { max-width: 100%; }
    table.np-stack > tbody > tr > td > div, table.np-stack > tbody > tr > td > form { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
    table.np-stack > tbody > tr > td .btn { flex: 0 0 auto; margin: 0; }
    table.np-stack > tfoot > tr > td, table.np-stack > tfoot > tr > th { display: block; text-align: right !important; padding: 6px 0; border: 0; }
    .table-responsive.np-stack-wrap { overflow: visible; }
}

/* ছোট ল্যান্ডস্কেপ ফোন */
@media (max-height: 480px) and (orientation: landscape) {
    .np-bottomnav { display: none; }
    body { padding-bottom: 0; }
    .np-install { bottom: 10px; }
}

/* বড় ডেস্কটপ: ড্রয়ার-ইউআই সম্পূর্ণ লুকানো */
@media (min-width: 992px) {
    .np-overlay, .np-bottomnav, .np-menu-btn { display: none !important; }
}

/* অ্যাপ হিসেবে ইনস্টল করা থাকলে */
html.np-standalone body { overscroll-behavior-y: contain; }
html.np-standalone .np-install { display: none !important; }

/* প্রিন্টে অ্যাপ-ইউআই নয় */
@media print {
    .np-overlay, .np-bottomnav, .np-install, .np-menu-btn, .np-back-btn, .np-install-top, .np-sidebar-close { display: none !important; }
    body { padding-bottom: 0 !important; }
    table.np-stack { display: table !important; }
}

/* কম মোশন পছন্দ করলে */
@media (prefers-reduced-motion: reduce) {
    .sidebar, .np-overlay, .np-install { transition: none !important; }
}

/* ডেস্কটপ: টপ-বারে POS আগে, ইউজারের নাম পরে */
@media (min-width: 992px) {
    .np-top-right .np-pos-top { order: -1; }
}

/* ফোন: ড্যাশবোর্ডের ৪টি স্ট্যাট কার্ড ২×২, ছোট ফন্ট */
@media (max-width: 575.98px) {
    .main-content .modern-card.p-4 { padding: 12px !important; }
    .main-content .modern-card .stat-label { font-size: 10px; letter-spacing: .4px; }
    .main-content .modern-card .stat-value { font-size: 15px; margin-top: 2px; word-break: break-word; }
    .main-content .modern-card .stat-icon { font-size: 44px; right: -6px; bottom: -6px; }
}
