/* =============================================================
   YSD B2B - Mobile & Tablet Stylesheet
   ปรับ UI ให้ใช้งานบนมือถือ/แท็บเล็ตได้สะดวกและสวยงามขึ้น
   ไม่กระทบหน้าเว็บบนเดสก์ท็อป (ทุก rule อยู่ใต้ @media)

   Breakpoints:
     - ≤ 1024px         : ใช้ร่วมกันระหว่างมือถือ + แท็บเล็ต
     - 769px – 1024px   : Tablet (2-col card grid, ปุ่มใหญ่ขึ้น)
     - ≤ 768px          : Mobile (1-col cards, bottom nav, ฯลฯ)
     - ≤ 380px          : โทรศัพท์เล็ก
   ============================================================= */

:root {
    --m-radius-lg: 14px;
    --m-radius-md: 10px;
    --m-touch: 44px;
    --m-shadow-card: 0 2px 8px -2px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
    --m-shadow-pop: 0 8px 24px -6px rgba(15, 23, 42, 0.15);
    --m-nav-height: 64px;
}

.mobile-bottom-nav { display: none; }

/* =============================================================
   Tablet & Mobile (≤ 1024px) — ใช้ร่วมกัน
   ============================================================= */
@media (max-width: 1024px) {
    .navbar { padding: 0.85rem 1.25rem; }
    .navbar-brand { font-size: 1.15rem; }
    .secondary-nav {
        padding: 0 1rem;
        overflow-x: auto;
        gap: 0.5rem;
        scrollbar-width: none;
    }
    .secondary-nav::-webkit-scrollbar { display: none; }
    main { padding: 1.25rem; }

    /* ป้องกัน iOS zoom เวลาแตะช่อง */
    input[type="text"], input[type="number"], input[type="email"],
    input[type="password"], input[type="search"], select, textarea {
        font-size: 16px !important;
    }

    /* Touch target ขั้นต่ำ 44px ทุก breakpoint */
    button, .btn, [class^="btn-"], [class*=" btn-"] {
        min-height: var(--m-touch);
    }
}

/* =============================================================
   Tablet — portrait: แสดง bottom nav ด้วย (thumb reach)
   ============================================================= */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
    body {
        padding-bottom: calc(var(--m-nav-height) + env(safe-area-inset-bottom, 0px));
    }
    .mobile-bottom-nav {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        position: fixed;
        bottom: 0; left: 0; right: 0;
        z-index: 1100;
        background: rgba(255, 255, 255, 0.97);
        backdrop-filter: saturate(180%) blur(12px);
        -webkit-backdrop-filter: saturate(180%) blur(12px);
        border-top: 1px solid var(--border-color, #e2e8f0);
        box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.06);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        height: calc(var(--m-nav-height) + env(safe-area-inset-bottom, 0px));
    }
    .mbn-item {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        color: #64748b;
        text-decoration: none;
        font-size: 0.8rem;
        font-weight: 600;
        padding: 0.5rem;
    }
    .mbn-item i { font-size: 1.35rem; }
    .mbn-item.active { color: var(--primary-color, #1e40af); }
    .mbn-item.active::before {
        content: "";
        position: absolute;
        top: 0; left: 50%;
        transform: translateX(-50%);
        width: 32px; height: 3px;
        background: var(--primary-color, #1e40af);
        border-radius: 0 0 3px 3px;
    }
    .mbn-badge {
        position: absolute;
        top: 6px;
        right: calc(50% - 26px);
        background: #ef4444;
        color: #fff;
        border-radius: 999px;
        padding: 1px 6px;
        font-size: 0.7rem;
        font-weight: 800;
        border: 2px solid white;
        min-width: 18px;
        text-align: center;
    }
    #backToTop {
        bottom: calc(var(--m-nav-height) + 14px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* =============================================================
   Tablet (769–1024px) — Layout 2 คอลัมน์, ตารางสบายตา
   ============================================================= */
@media (min-width: 769px) and (max-width: 1024px) {

    main { padding: 1.5rem 1.25rem; }

    .page-header {
        padding: 1.25rem 1.5rem !important;
        flex-wrap: wrap;
        gap: 1rem;
    }

    .filter-container {
        flex-wrap: wrap;
        gap: 0.75rem !important;
        padding: 1rem !important;
    }
    .filter-container .form-group-inline {
        flex: 1 1 280px;
        display: flex;
        gap: 0.5rem;
    }
    .filter-container .btn-search {
        flex: 0 0 auto;
        min-width: 120px;
    }

    /* Product list → 2-col card grid */
    .product-list-container, .table-container {
        overflow-x: visible;
        padding: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        border: 0 !important;
    }
    .product-table {
        display: block;
        background: transparent;
        border-collapse: separate;
        border-spacing: 0;
    }
    .product-table thead { display: none; }
    .product-table tbody {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }
    .product-table tbody tr {
        display: grid;
        grid-template-columns: auto 1fr;
        grid-template-areas:
            "code name"
            "unit name"
            "price price"
            "discount net"
            "action action";
        gap: 0.5rem 0.85rem;
        background: var(--card-bg, #fff);
        border: 1px solid var(--border-color, #e2e8f0);
        border-radius: var(--m-radius-lg);
        padding: 1rem;
        box-shadow: var(--m-shadow-card);
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }
    .product-table tbody tr:hover {
        transform: translateY(-2px);
        box-shadow: var(--m-shadow-pop);
        background: #fff !important;
    }
    .product-table tbody tr:nth-child(even) { background: var(--card-bg, #fff) !important; }
    .product-table tbody td {
        display: block;
        padding: 0;
        border: 0;
        text-align: left !important;
    }
    .product-table tbody td:nth-of-type(1) { grid-area: code; }
    .product-table tbody td:nth-of-type(2) { grid-area: name; }
    .product-table tbody td:nth-of-type(3) { grid-area: unit; }
    .product-table tbody td:nth-of-type(4) {
        grid-area: price;
        text-align: left !important;
        padding-top: 0.5rem;
        border-top: 1px dashed var(--border-color, #e2e8f0);
    }
    .product-table tbody td:nth-of-type(4)::before {
        content: "ราคาขาย: ";
        color: var(--text-muted, #475569);
        font-size: 0.82rem;
        margin-right: 0.35rem;
    }
    .product-table tbody td:nth-of-type(5) { grid-area: discount; }
    .product-table tbody td:nth-of-type(5)::before {
        content: "ส่วนลด: ";
        color: var(--text-muted, #475569);
        font-size: 0.82rem;
        margin-right: 0.35rem;
    }
    .product-table tbody td:nth-of-type(6) {
        grid-area: net;
        text-align: right !important;
    }
    .product-table tbody td:nth-of-type(6)::before {
        content: "สุทธิ: ";
        color: var(--text-muted, #475569);
        font-size: 0.82rem;
        margin-right: 0.35rem;
        font-weight: 400;
    }
    .product-table tbody td:nth-of-type(6) .net-price-text {
        font-size: 1.2rem;
        font-weight: 700;
        color: #166534;
    }
    .product-table tbody td:nth-of-type(7) { grid-area: action; }

    .product-info-cell .product-name {
        font-size: 1rem;
        font-weight: 600;
        line-height: 1.4;
    }
    .product-info-cell .product-name-eng {
        font-size: 0.85rem;
        color: var(--text-muted, #475569);
    }

    .action-cell {
        display: grid !important;
        grid-template-columns: auto 1fr;
        gap: 0.75rem;
        align-items: center;
        margin-top: 0.35rem;
    }
    .qty-control {
        display: flex;
        align-items: center;
        gap: 0.35rem;
        background: #f1f5f9;
        border-radius: 999px;
        padding: 4px;
    }
    .qty-control .btn-qty {
        background: white;
        border-radius: 50%;
        border: 0;
        width: 40px; height: 40px;
        min-height: 40px;
        display: flex; align-items: center; justify-content: center;
        box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    }
    .qty-control .qty-input {
        width: 54px;
        text-align: center;
        border: 0;
        background: transparent;
        font-weight: 700;
        padding: 0;
        font-size: 1rem;
    }
    .btn-add-cart {
        font-size: 0.95rem;
        padding: 0.7rem 1rem;
        border-radius: 999px;
        font-weight: 600;
    }

    /* Cart — เก็บเป็นตาราง แต่แถวใหญ่ขึ้น */
    .cart-table th, .cart-table td {
        padding: 0.9rem 0.75rem !important;
        font-size: 0.95rem;
    }
    .cart-table .item-name { font-weight: 600; font-size: 1rem; }
    .cart-table .item-subtotal { font-size: 1.1rem; font-weight: 700; }
    .btn-remove { min-height: 40px; padding: 0.5rem 0.75rem; }

    .cart-actions {
        flex-wrap: wrap !important;
        gap: 0.75rem !important;
        padding: 1.25rem !important;
    }
    .cart-actions > * {
        min-height: var(--m-touch);
        flex: 1 1 200px;
    }
    .cart-summary {
        padding: 1.25rem !important;
        font-size: 1rem;
    }

    /* Modal — เต็มจอเล็ก ๆ */
    .modal-box {
        max-width: 540px !important;
        width: 92% !important;
        max-height: 88vh !important;
    }
    .modal-actions {
        flex-direction: row !important;
        justify-content: flex-end;
        gap: 0.75rem;
    }

    /* Dashboard */
    .quick-links {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1rem !important;
    }
    .quick-link-card {
        padding: 1.5rem !important;
        min-height: 120px;
    }
    .welcome-section h1 { font-size: 1.75rem !important; }

    /* My Orders / Order Management */
    .orders-list {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }
    .order-card { padding: 1rem !important; }

    /* Pagination */
    .pagination-bar {
        gap: 0.5rem !important;
        padding: 1rem !important;
    }
    .pagination-bar .page-btn {
        min-width: var(--m-touch);
        min-height: var(--m-touch);
        padding: 0.55rem 0.85rem;
    }

    .qty-input { min-height: 40px; }

    /* Other tables — horizontal scroll fallback */
    main table:not(.product-table):not(.cart-table) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* =============================================================
   Mobile (≤ 768px) — Layout 1 คอลัมน์, bottom nav, ฯลฯ
   ============================================================= */
@media (max-width: 768px) {

    html { -webkit-text-size-adjust: 100%; }
    body {
        font-size: 15px;
        padding-bottom: calc(var(--m-nav-height) + env(safe-area-inset-bottom, 0px));
    }
    img { max-width: 100%; height: auto; }

    /* Top Navbar */
    .navbar {
        padding: 0.75rem 1rem;
        box-shadow: 0 1px 0 rgba(0,0,0,0.05), 0 2px 8px -4px rgba(0,0,0,0.12);
    }
    .navbar-brand {
        font-size: 0.95rem;
        line-height: 1.2;
        max-width: 75%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .navbar-brand span { font-size: inherit; }

    /* Secondary Nav */
    .secondary-nav {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        flex-wrap: nowrap;
        position: sticky;
        top: 56px;
        z-index: 999;
    }
    .secondary-nav .user-info-chip {
        flex-shrink: 0;
        font-size: 0.85rem;
        padding: 0.4rem 0.75rem;
    }
    .secondary-nav .nav-items {
        gap: 0.25rem;
        flex-shrink: 0;
    }
    .secondary-nav a {
        padding: 0.5rem 0.8rem;
        font-size: 0.85rem;
        flex-shrink: 0;
    }
    .secondary-nav .logout-form { flex-shrink: 0; }
    .secondary-nav .logout-btn,
    .secondary-nav .btn-logout {
        padding: 0.5rem 0.85rem;
        font-size: 0.85rem;
        min-height: var(--m-touch);
    }

    main { padding: 1rem 0.85rem; }

    /* Page header */
    .page-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.75rem;
        padding: 1rem !important;
    }
    .page-header h1, .page-header h2 { font-size: 1.15rem !important; }

    /* Inputs */
    input[type="text"], input[type="number"], input[type="email"],
    input[type="password"], input[type="search"], select, textarea,
    .qty-input, .custom-select {
        font-size: 16px !important;
        min-height: var(--m-touch);
    }
    button, .btn, [class^="btn-"], [class*=" btn-"] {
        min-height: var(--m-touch);
    }
    .btn-qty {
        width: var(--m-touch);
        height: var(--m-touch);
        font-size: 1rem;
    }

    /* Filter / Search bar */
    .filter-container {
        flex-direction: column;
        gap: 0.5rem !important;
        padding: 0.85rem !important;
    }
    .filter-container > * { width: 100%; }
    .form-group-inline {
        width: 100%;
        display: flex;
        gap: 0.5rem;
    }
    .form-group-inline input,
    .form-group-inline select { flex: 1; min-width: 0; }
    .btn-search { width: 100%; }

    /* Product list — 1-col card mode */
    .product-list-container, .table-container {
        overflow-x: visible;
        padding: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        border: 0 !important;
    }
    .product-table {
        display: block;
        background: transparent;
        border-collapse: separate;
        border-spacing: 0;
    }
    .product-table thead { display: none; }
    .product-table tbody {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    .product-table tbody tr {
        display: grid;
        grid-template-columns: auto 1fr;
        grid-template-areas:
            "code name"
            "unit name"
            "price price"
            "discount net"
            "action action";
        gap: 0.4rem 0.75rem;
        background: var(--card-bg, #fff);
        border: 1px solid var(--border-color, #e2e8f0);
        border-radius: var(--m-radius-lg);
        padding: 0.85rem;
        box-shadow: var(--m-shadow-card);
    }
    .product-table tbody td {
        display: block;
        padding: 0;
        border: 0;
        text-align: left !important;
    }
    .product-table tbody td:nth-of-type(1) { grid-area: code; }
    .product-table tbody td:nth-of-type(2) { grid-area: name; }
    .product-table tbody td:nth-of-type(3) { grid-area: unit; }
    .product-table tbody td:nth-of-type(4) {
        grid-area: price;
        text-align: left !important;
        padding-top: 0.4rem;
        border-top: 1px dashed var(--border-color, #e2e8f0);
    }
    .product-table tbody td:nth-of-type(4)::before {
        content: "ราคาขาย: ";
        color: var(--text-muted, #475569);
        font-size: 0.8rem;
        margin-right: 0.35rem;
    }
    .product-table tbody td:nth-of-type(5) { grid-area: discount; }
    .product-table tbody td:nth-of-type(5)::before {
        content: "ส่วนลด: ";
        color: var(--text-muted, #475569);
        font-size: 0.8rem;
        margin-right: 0.35rem;
    }
    .product-table tbody td:nth-of-type(6) {
        grid-area: net;
        text-align: right !important;
    }
    .product-table tbody td:nth-of-type(6)::before {
        content: "สุทธิ: ";
        color: var(--text-muted, #475569);
        font-size: 0.8rem;
        margin-right: 0.35rem;
        font-weight: 400;
    }
    .product-table tbody td:nth-of-type(6) .net-price-text {
        font-size: 1.15rem;
        font-weight: 700;
        color: #166534;
    }
    .product-table tbody td:nth-of-type(7) { grid-area: action; }

    .product-info-cell .product-name {
        font-size: 0.98rem;
        font-weight: 600;
        line-height: 1.35;
    }
    .product-info-cell .product-name-eng {
        font-size: 0.82rem;
        color: var(--text-muted, #475569);
    }

    .action-cell {
        display: grid !important;
        grid-template-columns: 1fr auto;
        gap: 0.6rem;
        align-items: center;
        margin-top: 0.25rem;
    }
    .qty-control {
        display: flex;
        align-items: center;
        gap: 0.25rem;
        background: #f1f5f9;
        border-radius: 999px;
        padding: 3px;
    }
    .qty-control .btn-qty {
        background: white;
        border-radius: 50%;
        border: 0;
        width: 38px; height: 38px;
        min-height: 38px;
        display: flex; align-items: center; justify-content: center;
        box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    }
    .qty-control .qty-input {
        width: 48px;
        text-align: center;
        border: 0;
        background: transparent;
        font-weight: 700;
        padding: 0;
    }
    .btn-add-cart {
        font-size: 0.9rem;
        padding: 0.65rem 0.9rem;
        border-radius: 999px;
    }

    /* Cart — card mode */
    .cart-container {
        padding: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
    }
    .cart-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
        padding: 1rem !important;
    }
    .cart-table-card {
        padding: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
    }
    .cart-table {
        display: block;
        border-collapse: separate;
        border-spacing: 0;
    }
    .cart-table thead { display: none; }
    .cart-table tbody {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.6rem;
    }
    .cart-table tbody tr {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "code remove"
            "name name"
            "price discount"
            "net qty"
            "subtotal subtotal";
        gap: 0.35rem 0.5rem;
        background: var(--card-bg, #fff);
        border: 1px solid var(--border-color, #e2e8f0);
        border-radius: var(--m-radius-lg);
        padding: 0.85rem;
        box-shadow: var(--m-shadow-card);
    }
    .cart-table tbody td {
        display: block;
        padding: 0;
        border: 0;
        text-align: left !important;
        font-size: 0.92rem;
    }
    .cart-table tbody td:nth-of-type(1) { grid-area: code; }
    .cart-table tbody td:nth-of-type(2) { grid-area: name; }
    .cart-table tbody td:nth-of-type(2) .item-name {
        font-weight: 600; font-size: 1rem;
    }
    .cart-table tbody td:nth-of-type(3) { grid-area: price; }
    .cart-table tbody td:nth-of-type(3)::before {
        content: "ราคา: ";
        color: var(--text-muted);
        font-size: 0.78rem;
    }
    .cart-table tbody td:nth-of-type(4) {
        grid-area: discount;
        text-align: right !important;
    }
    .cart-table tbody td:nth-of-type(4)::before {
        content: "ส่วนลด: ";
        color: #94a3b8;
        font-size: 0.78rem;
        font-weight: 400;
    }
    .cart-table tbody td:nth-of-type(5) { grid-area: net; }
    .cart-table tbody td:nth-of-type(5)::before {
        content: "สุทธิ: ";
        color: var(--text-muted);
        font-size: 0.78rem;
    }
    .cart-table tbody td:nth-of-type(6) {
        grid-area: qty;
        text-align: right !important;
    }
    .cart-table tbody td:nth-of-type(6)::before {
        content: "จำนวน: ";
        color: var(--text-muted);
        font-size: 0.78rem;
    }
    .cart-table tbody td:nth-of-type(7) {
        grid-area: subtotal;
        text-align: right !important;
        border-top: 1px dashed var(--border-color);
        padding-top: 0.5rem !important;
        margin-top: 0.25rem;
    }
    .cart-table tbody td:nth-of-type(7)::before {
        content: "รวม ฿ ";
        color: var(--text-muted);
        font-size: 0.85rem;
        font-weight: 500;
    }
    .cart-table tbody td:nth-of-type(7) .item-subtotal {
        font-size: 1.2rem; font-weight: 800; color: #166534;
    }
    .cart-table tbody td:nth-of-type(8) {
        grid-area: remove;
        justify-self: end;
    }
    .btn-remove { padding: 0.35rem 0.6rem; }

    .cart-actions {
        flex-direction: column !important;
        gap: 0.6rem !important;
        padding: 1rem !important;
    }
    .cart-actions > * { width: 100%; justify-content: center; }
    .btn-checkout, .btn-clear, .btn-continue {
        width: 100%; text-align: center; font-size: 1rem;
    }
    .cart-summary {
        position: sticky;
        bottom: calc(var(--m-nav-height) + 4px);
        margin-top: 1rem;
        background: white;
        border-radius: var(--m-radius-lg);
        box-shadow: var(--m-shadow-pop);
        padding: 1rem !important;
    }

    /* Modal — bottom sheet */
    .modal-backdrop {
        align-items: flex-end !important;
        padding: 0 !important;
    }
    .modal-box {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 92vh !important;
        margin: 0 !important;
        border-bottom-left-radius: 0 !important;
        border-bottom-right-radius: 0 !important;
        border-radius: 20px 20px 0 0 !important;
        animation: mSlideUp 0.25s ease-out;
    }
    @keyframes mSlideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    .modal-actions {
        flex-direction: column-reverse !important;
        gap: 0.5rem;
    }
    .modal-actions > * { width: 100%; }

    /* Dashboard */
    .quick-links {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }
    .quick-link-card {
        padding: 1rem !important;
        min-height: 88px;
    }
    .welcome-section h1 { font-size: 1.35rem !important; }
    .dashboard-banner img { width: 100%; height: auto; }

    /* My Orders */
    .order-card { padding: 0.85rem !important; }
    .order-card-body {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .btn-detail {
        width: 100%;
        justify-content: center;
    }
    .mo-container, .om-container {
        padding: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
    }

    /* Pagination */
    .pagination-bar {
        flex-wrap: wrap;
        gap: 0.35rem !important;
        padding: 0.75rem !important;
        justify-content: center;
    }
    .pagination-bar .page-btn {
        min-width: var(--m-touch);
        padding: 0.5rem 0.75rem;
    }
    .pagination-bar .page-info {
        width: 100%;
        text-align: center;
        order: -1;
    }

    /* Other tables — horizontal scroll fallback */
    main table:not(.product-table):not(.cart-table) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Back to top */
    #backToTop {
        bottom: calc(var(--m-nav-height) + 14px + env(safe-area-inset-bottom, 0px)) !important;
        right: 14px !important;
        width: 44px !important;
        height: 44px !important;
    }

    /* Mobile Bottom Navigation */
    .mobile-bottom-nav {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1100;
        background: rgba(255, 255, 255, 0.97);
        backdrop-filter: saturate(180%) blur(12px);
        -webkit-backdrop-filter: saturate(180%) blur(12px);
        border-top: 1px solid var(--border-color, #e2e8f0);
        box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.06);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        height: calc(var(--m-nav-height) + env(safe-area-inset-bottom, 0px));
    }
    .mbn-item {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        color: #64748b;
        text-decoration: none;
        font-size: 0.72rem;
        font-weight: 600;
        padding: 0.4rem 0.25rem;
        transition: color 0.15s ease, transform 0.15s ease;
    }
    .mbn-item i { font-size: 1.2rem; line-height: 1; }
    .mbn-item:active { transform: scale(0.92); }
    .mbn-item.active { color: var(--primary-color, #1e40af); }
    .mbn-item.active::before {
        content: "";
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 28px; height: 3px;
        background: var(--primary-color, #1e40af);
        border-radius: 0 0 3px 3px;
    }
    .mbn-badge {
        position: absolute;
        top: 4px;
        right: calc(50% - 22px);
        background: #ef4444;
        color: #fff;
        border-radius: 999px;
        padding: 1px 6px;
        font-size: 0.65rem;
        font-weight: 800;
        border: 2px solid white;
        line-height: 1.2;
        min-width: 18px;
        text-align: center;
    }
}

/* =============================================================
   Very small phones (≤ 380px)
   ============================================================= */
@media (max-width: 380px) {
    .navbar { padding: 0.65rem 0.85rem; }
    .navbar-brand { font-size: 0.85rem; }
    main { padding: 0.85rem 0.7rem; }
    .mbn-item { font-size: 0.68rem; }
    .mbn-item i { font-size: 1.1rem; }
    .product-table tbody tr,
    .cart-table tbody tr { padding: 0.7rem; }
}

/* =============================================================
   ป้องกัน hover stuck บน touch device
   ============================================================= */
@media (hover: none) {
    a:hover, button:hover { transform: none !important; }
}
