/* ============================================================
   Mobile App Skin — เฉพาะ "เลย์เอาต์/โครงสร้าง" บนจอ <= 992px
   ------------------------------------------------------------
   • สี/ฟอนต์/มุมโค้ง/เงา ทั้งหมดดึงจาก theme.css (Style Master)
     ไฟล์นี้ "ไม่ตั้งค่าสีเอง" เพื่อให้ desktop/mobile ใช้โทนเดียวกัน ไม่โดดไปมา
   • ทำเฉพาะสิ่งที่ต้องต่างจริงบนมือถือ: app-bar, การ์ดลิสต์, กริดเมนู,
     แถบล่าง, ขนาดสัมผัส, ฟอนต์ mono สำหรับรหัส/ตัวเลข
   ============================================================ */

@media (max-width: 992px) {

    /* topbar บนมือถือสูง 52px → sync ตัวแปรกลาง ให้ทุกอย่างที่ยึด --topbar-height
       (แท็บหมวด / แถบค้นหาลอย / drawer) แนบใต้ navbar พอดี ไม่มีช่องว่างลอย 8px */
    :root { --topbar-height: 52px; }

    /* รหัส/ตัวเลขใช้ฟอนต์ mono (semantic ไม่ใช่การเปลี่ยนสี) */
    .num, .mono, .table-app .num, .topbar-user__avatar {
        font-family: var(--ff-mono);
        font-variant-numeric: tabular-nums;
    }

    /* ---- App-bar: ชื่อกลาง (จัดกลางจาก site.css) ---- */
    .app-topbar {
        background: var(--color-bg);
        border-bottom: 1px solid var(--color-border);
        height: 52px;
        padding: 0 var(--space-3);
    }
    .app-topbar__title { font-size: 17px; font-weight: 600; }
    .topbar-toggle, .topbar-back { color: var(--color-text); }

    .card-app__title { font-size: 14px; }

    /* ปุ่ม: เพิ่ม feedback ตอนแตะ (สีใช้จาก theme เหมือน desktop) */
    .btn-app:active { transform: scale(0.985); }

    /* ---- ลิสต์เอกสารแบบการ์ด (docrow) ---- */
    .table-app.table-cards tbody tr {
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        background: var(--color-surface);
        padding: 12px 14px;
        margin-bottom: 10px;
        box-shadow: var(--shadow-sm);
    }
    .table-app.table-cards tbody tr:active { background: var(--color-surface-alt); }
    .table-app.table-cards tbody td { padding: 4px 0; }
    .table-app.table-cards tbody td::before {
        font-family: var(--ff-mono);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        font-size: 10px;
        color: var(--color-faint);
    }
    .table-app.table-cards tbody td:first-child strong {
        font-family: var(--ff-mono);
        font-size: 14px;
    }

    /* Pick list: keep long transfer references and action buttons inside the card. */
    .pick-list-table { table-layout: fixed; }
    .pick-list-table.table-cards { width: 100%; }
    .pick-list-table.table-cards thead { display: none; }
    .pick-list-table.table-cards tbody { display: block; width: 100%; }
    .pick-list-table.table-cards tbody tr {
        display: grid;
        width: 100%;
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 4px 10px;
        padding: 10px 12px 8px;
        margin-bottom: 7px;
        font-size: 13px;
    }
    .pick-list-table.table-cards tbody tr,
    .pick-list-table.table-cards tbody td { min-width: 0; max-width: 100%; }
    .pick-list-table.table-cards tbody td {
        display: flex;
        width: 100%;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        border: 0;
        padding: 2px 0;
    }
    .pick-list-table.table-cards tbody td::before {
        content: attr(data-label);
        flex: 0 0 clamp(86px, 15vw, 118px);
        font-weight: 600;
        color: var(--color-muted);
        font-size: 11px;
        line-height: 1.35;
    }
    .pick-list-table.table-cards tbody td.pick-transfer-cell {
        display: grid;
        grid-template-columns: clamp(86px, 15vw, 118px) minmax(0, 1fr);
    }
    .pick-list-table.table-cards tbody td.pick-transfer-cell > * {
        grid-column: 2;
        min-width: 0;
        max-width: 100%;
        white-space: normal !important;
        overflow-wrap: anywhere;
    }
    .pick-list-table.table-cards tbody td.pick-transfer-cell::before {
        grid-column: 1;
        grid-row: 1;
    }
    .pick-list-table.table-cards .pick-trb-open { white-space: normal; overflow-wrap: anywhere; }
    .pick-list-table.table-cards tbody td:nth-child(1) {
        grid-column: 1;
        grid-row: 1;
        width: auto;
        align-items: center;
    }
    .pick-list-table.table-cards tbody td:nth-child(2) {
        grid-column: 2;
        grid-row: 1;
        width: 100%;
        padding: 0;
        align-items: center;
        text-align: left;
    }
    .pick-list-table.table-cards tbody td:nth-child(2)::before { display: none; }
    .pick-list-table.table-cards tbody td:nth-child(2) strong {
        font-size: 15px;
        line-height: 1.3;
    }
    .pick-list-table.table-cards tbody td:nth-child(3) {
        grid-column: 2 / -1;
        grid-row: 3;
        justify-content: flex-start;
        gap: 8px;
    }
    .pick-list-table.table-cards tbody td:nth-child(3)::before { flex-basis: auto; }
    .pick-list-table.table-cards tbody td:nth-child(4) {
        grid-column: 1 / -1;
        grid-row: 2;
        margin-top: 4px;
        padding: 8px 0 6px;
        border-top: 1px solid var(--color-border);
    }
    .pick-list-table.table-cards tbody td:nth-child(5) {
        grid-column: 1 / 3;
        grid-row: 4;
        width: auto;
        justify-content: flex-start;
        align-items: center;
        gap: 6px;
    }
    .pick-list-table.table-cards tbody td:nth-child(5)::before { flex-basis: auto; }
    .pick-list-table.table-cards tbody td:nth-child(6) {
        grid-column: 3;
        grid-row: 1;
        width: auto;
        padding: 0;
        align-items: center;
    }
    .pick-list-table.table-cards tbody td:nth-child(6)::before { display: none; }
    .pick-list-table.table-cards tbody td:nth-child(7) {
        grid-column: 3;
        grid-row: 4;
        width: auto;
        margin: 0;
        padding: 0;
        border: 0;
    }
    .pick-list-table.table-cards tbody td[data-label=""]::before { display: none; }
    .pick-list-table.table-cards tbody td[data-label=""] .row-actions {
        width: 100%;
        justify-content: flex-end;
    }
    .pick-list-table.table-cards .row-actions { gap: 6px; }
    .pick-list-table.table-cards .row-actions .btn-icon-app {
        max-width: 100%;
        min-height: 32px;
        width: auto;
        height: 32px;
        padding: 0 9px;
        font-size: 12px;
        border-radius: var(--radius-md);
        gap: 5px;
    }
    .pick-list-table.table-cards .row-actions .btn-icon-app::after {
        display: inline;
        font-size: 11px;
        white-space: nowrap;
    }
    #pickResult > .mb-2 { margin-bottom: 5px !important; }
    #pickResult > .card-app { margin-bottom: 12px !important; }
    #pickResult > .card-app .card-app__header { padding-block: 9px; }
    #pickResult .card-app > .table-scroll { overflow: visible; }

    /* Pick phone: keep summary and actions on separate rows so labels never overlap. */
    @media (max-width: 600px) {
        .pick-list-table.table-cards tbody tr {
            grid-template-rows: auto auto auto auto;
            gap: 0 10px;
            padding: 0;
            margin-bottom: 16px;
            font-size: 14px;
            overflow: hidden;
            border: 1px solid var(--color-border-strong);
            border-left: 4px solid var(--color-primary);
            border-radius: var(--radius-lg);
            background: var(--color-surface);
            box-shadow: 0 3px 10px rgba(15, 23, 42, .10);
        }
        .pick-list-table.table-cards tbody tr:last-child { margin-bottom: 0; }
        .pick-list-table.table-cards tbody td { line-height: 1.45; }
        .pick-list-table.table-cards tbody td:nth-child(1) {
            padding: 14px 0 12px 14px;
        }
        .pick-list-table.table-cards tbody td:nth-child(2) {
            padding: 14px 0 12px;
        }
        .pick-list-table.table-cards tbody td:nth-child(2) strong {
            font-size: 16px;
            line-height: 1.35;
        }
        .pick-list-table.table-cards tbody td:nth-child(3) {
            display: none !important;
        }
        .pick-list-table.table-cards tbody td:nth-child(5)::before {
            font-size: 12px;
            color: var(--color-muted);
        }
        .pick-list-table.table-cards tbody td:nth-child(6) {
            padding: 12px 14px 10px 0;
        }
        .pick-list-table.table-cards tbody td:nth-child(4) {
            display: flex;
            flex-direction: column;
            gap: 5px;
            margin: 0 12px;
            padding: 11px 12px;
            background: var(--color-surface-alt);
            border: 1px solid var(--color-border);
            border-radius: var(--radius-md);
        }
        .pick-list-table.table-cards tbody td:nth-child(4)::before {
            display: block;
            flex: none;
            font-size: 11px;
            letter-spacing: .04em;
        }
        .pick-list-table.table-cards tbody td:nth-child(4) > * {
            grid-column: auto;
            min-width: 0;
            white-space: normal !important;
            overflow-wrap: anywhere;
        }
        .pick-list-table.table-cards .pick-trb-open {
            font-size: 14px;
            line-height: 1.4;
        }
        .pick-list-table.table-cards tbody td.pick-transfer-cell .text-muted {
            font-size: 12px !important;
            line-height: 1.55;
        }
        .pick-list-table.table-cards tbody td:nth-child(5) {
            grid-column: 1 / -1;
            grid-row: 3;
            width: 100%;
            padding: 11px 14px;
            margin-top: 9px;
            border-top: 1px solid var(--color-border);
            font-size: 15px;
            font-weight: 700;
        }
        .pick-list-table.table-cards tbody td:nth-child(7) {
            grid-column: 1 / -1;
            grid-row: 4;
            width: 100%;
            margin-top: 0;
            padding: 10px 12px 12px;
            border-top: 1px solid var(--color-border);
            background: var(--color-surface-alt);
        }
        #pickResult > .card-app .table-scroll {
            margin: 0;
            padding: 12px 8px;
            background: var(--color-neutral-soft);
            border-top: 1px solid var(--color-border);
        }
        .pick-list-table.table-cards tbody td[data-label=""] .row-actions {
            display: grid;
            grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
            gap: 6px;
            justify-content: stretch;
        }
        .pick-list-table.table-cards .row-actions .btn-icon-app {
            width: 100%;
            min-width: 0;
            padding-inline: 7px;
        }
    }

    /* Pick tablet: three clear reading zones — document, transfer, actions. */
    @media (min-width: 601px) {
        .pick-list-table.table-cards tbody tr {
            grid-template-columns: minmax(190px, .9fr) minmax(220px, 1.15fr) minmax(215px, auto);
            grid-template-rows: auto minmax(38px, 1fr) auto;
            column-gap: 0;
            min-height: 126px;
        }
        .pick-list-table.table-cards tbody td:nth-child(1) {
            grid-column: 1;
            grid-row: 1;
            align-self: start;
        }
        .pick-list-table.table-cards tbody td:nth-child(2) {
            grid-column: 1;
            grid-row: 1;
            padding-left: 27px;
        }
        .pick-list-table.table-cards tbody td:nth-child(3) {
            grid-column: 1;
            grid-row: 2;
            align-self: center;
            padding-right: 14px;
        }
        .pick-list-table.table-cards tbody td:nth-child(4) {
            grid-column: 2;
            grid-row: 1 / 4;
            align-self: stretch;
            align-content: center;
            margin: 0;
            padding: 8px 18px;
            border-top: 0;
            grid-template-columns: minmax(0, 1fr);
            row-gap: 6px;
        }
        .pick-list-table.table-cards tbody td:nth-child(4)::before {
            grid-column: 1;
            grid-row: 1;
        }
        .pick-list-table.table-cards tbody td:nth-child(4) > * {
            grid-column: 1;
            grid-row: auto;
        }
        .pick-list-table.table-cards tbody td:nth-child(5) {
            grid-column: 1;
            grid-row: 3;
            align-self: end;
            padding-right: 14px;
        }
        .pick-list-table.table-cards tbody td:nth-child(6) {
            grid-column: 3;
            grid-row: 1;
            justify-self: end;
            padding-left: 0;
        }
        .pick-list-table.table-cards tbody td:nth-child(7) {
            grid-column: 3;
            grid-row: 3;
            justify-self: end;
            align-self: end;
            padding-left: 14px;
        }

        /* Shipping tablet: document / fulfillment data / status and action. */
        .ship-list-table.table-cards { width: 100%; table-layout: fixed; }
        .ship-list-table.table-cards thead { display: none; }
        .ship-list-table.table-cards tbody { display: block; width: 100%; }
        .ship-list-table.table-cards tbody tr {
            display: grid;
            width: 100%;
            grid-template-columns: minmax(195px, .9fr) minmax(220px, 1.2fr) minmax(130px, auto);
            grid-template-rows: repeat(4, auto);
            gap: 3px 0;
            min-height: 132px;
            padding: 10px 12px 8px;
            margin-bottom: 7px;
            font-size: 13px;
        }
        .ship-list-table.table-cards tbody td {
            display: flex;
            width: 100%;
            min-width: 0;
            max-width: 100%;
            align-items: flex-start;
            gap: 8px;
            padding: 2px 0;
            border: 0;
            overflow-wrap: anywhere;
        }
        .ship-list-table.table-cards tbody td::before {
            content: attr(data-label);
            flex: 0 0 72px;
            color: var(--color-muted);
            font-size: 11px;
            font-weight: 600;
            line-height: 1.35;
        }
        .ship-list-table.table-cards tbody td:nth-child(1) {
            grid-column: 1;
            grid-row: 1;
            width: auto;
            align-items: center;
        }
        .ship-list-table.table-cards tbody td:nth-child(1)::before,
        .ship-list-table.table-cards tbody td:nth-child(2)::before,
        .ship-list-table.table-cards tbody td:nth-child(8)::before,
        .ship-list-table.table-cards tbody td:nth-child(9)::before { display: none; }
        .ship-list-table.table-cards tbody td:nth-child(2) {
            grid-column: 1;
            grid-row: 1;
            padding-left: 27px;
        }
        .ship-list-table.table-cards tbody td:nth-child(2) .cell-stack {
            align-items: flex-start;
            text-align: left;
            gap: 2px;
        }
        .ship-list-table.table-cards tbody td:nth-child(2) strong {
            font-size: 15px;
            line-height: 1.25;
        }
        .ship-list-table.table-cards tbody td:nth-child(3) {
            grid-column: 2;
            grid-row: 1;
            align-self: center;
            padding: 2px 16px;
        }
        .ship-list-table.table-cards tbody td:nth-child(4),
        .ship-list-table.table-cards tbody td:nth-child(6) {
            grid-column: 2;
            padding: 2px 16px;
        }
        .ship-list-table.table-cards tbody td:nth-child(4) { grid-row: 2; }
        .ship-list-table.table-cards tbody td:nth-child(6) { grid-row: 3; }
        .ship-list-table.table-cards tbody td:nth-child(5),
        .ship-list-table.table-cards tbody td:nth-child(7) {
            grid-column: 1;
            padding-left: 27px;
            padding-right: 14px;
            display: grid;
            grid-template-columns: minmax(0, 1fr);
            gap: 1px;
            line-height: 1.3;
        }
        .ship-list-table.table-cards tbody td:nth-child(5)::before,
        .ship-list-table.table-cards tbody td:nth-child(7)::before {
            display: block;
            width: auto;
            white-space: nowrap;
            font-size: 10px;
        }
        .ship-list-table.table-cards tbody td:nth-child(5) { grid-row: 2; }
        .ship-list-table.table-cards tbody td:nth-child(7) { grid-row: 3; }
        .ship-list-table.table-cards tbody td:nth-child(7) {
            text-align: left;
            justify-items: start;
        }
        .ship-list-table.table-cards tbody td:nth-child(8) {
            grid-column: 3;
            grid-row: 1;
            width: auto;
            justify-self: end;
            padding: 0;
        }
        .ship-list-table.table-cards tbody td:nth-child(9) {
            grid-column: 3;
            grid-row: 4;
            width: auto;
            justify-self: end;
            align-self: end;
            padding: 0;
        }
        .ship-list-table.table-cards tbody td:nth-child(9) .row-actions {
            width: auto;
            padding: 0;
        }
        .ship-list-table.table-cards .ship-detail-btn {
            width: auto;
            height: 32px;
            padding: 0 10px;
            justify-content: center;
        }
        .ship-list-table.table-cards tbody tr[data-cardno]::after { display: none; }
        #shResult > .mb-2 { margin-bottom: 5px !important; }
        #shResult > .card-app { margin-bottom: 12px !important; }
        #shResult > .card-app .card-app__header { padding-block: 9px; }
        #shResult .card-app > .table-scroll { overflow: visible; }
    }
    /* Pick bulk export: two-row bottom action bar that stays inside the mobile viewport. */
    .pick-bulk-bar.pick-bulk-bar {
        left: 12px;
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        width: auto;
        max-width: none;
        transform: none;
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 8px;
        padding: 10px;
        border-radius: var(--radius-lg);
    }
    .pick-bulk-bar__count {
        grid-column: 1;
        grid-row: 1;
        align-self: center;
        min-width: 0;
    }
    .pick-bulk-bar #pickBulkClear {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
    }
    .pick-bulk-bar #pickBulkExport,
    .pick-bulk-bar #pickBulkExportPdf {
        grid-row: 2;
        width: 100%;
        min-width: 0;
        padding-inline: 8px;
        justify-content: center;
    }
    .pick-bulk-bar #pickBulkExport { grid-column: 1; }
    .pick-bulk-bar #pickBulkExportPdf { grid-column: 2; }
    /* ---- Filter bar เต็มกว้างแนบขอบ ---- */
    .filter-bar { border-radius: 0; border-left: 0; border-right: 0; box-shadow: none; }
    .input-app, .select-app, .search-input { border-radius: var(--radius-md); }

    /* หน้านับสต๊อก: ช่องค้นหา (แถบลอยใต้แท็บ) กระชับขึ้น ไม่กินพื้นที่แนวตั้ง */
    .count-sticky-head .count-search-bar { padding: 6px var(--space-3); gap: 8px; }
    .count-sticky-head .count-search-bar .input-app {
        min-height: 36px;
        padding-top: 6px;
        padding-bottom: 6px;
        font-size: 13px;
    }
    .count-sticky-head .count-progress { font-size: 12px; }
    /* ช่องค้นหายืดเต็มพื้นที่ที่เหลือ + หดได้ (min-width:0 มาจาก site.css) — คุมให้อยู่แถวเดียว
       ถ้าจอแคบจริง ๆ จนต้องตกบรรทัด ให้ตัวนับดันไปชิดขวา (margin-left:auto) เต็มแถว ไม่เหลือช่องว่างโล่ง */
    .count-sticky-head .count-search-bar__field { flex: 1 1 140px; max-width: none; }
    .count-sticky-head .count-progress { margin-left: auto; }
    /* Stock Count: ตัดช่องว่างจาก scrollbar ของแท็บ และให้ปุ่มบนสุดอยู่เหนือ save bar */
    .count-sticky-head .factory-tabs {
        margin-bottom: 0;
        padding-bottom: 0;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .count-sticky-head .factory-tabs::-webkit-scrollbar { display: none; width: 0; height: 0; }
    .count-to-top {
        right: 12px;
        bottom: calc(82px + env(safe-area-inset-bottom, 0px));
        z-index: 120;
    }

    /* หน้านับสต๊อก: การ์ดหัวเอกสารกระชับ — ฟิลด์เรียง 2 คอลัมน์ (2x2) ไม่กินทั้งจอ */
    .count-header-card { margin-bottom: var(--space-3); }
    .count-header-card .card-app__body { padding: var(--space-3); }
    .count-header-card .row.g-3 { --bs-gutter-y: 8px; --bs-gutter-x: 8px; }
    .count-header-card .row > [class*="col-"] { flex: 0 0 50%; max-width: 50%; }
    .count-header-card .field__label { font-size: 12px; margin-bottom: 2px; }
    .count-header-card .input-app { min-height: 38px; padding-top: 6px; padding-bottom: 6px; font-size: 13px; }

    /* page header: ชื่อหน้าซ้ำกับ app-bar อยู่แล้ว → ย่อคำโปรยให้เล็กลง ประหยัดพื้นที่ */
    .page-header__subtitle { font-size: 12px; }

    /* ---- Save bar -> bottom action bar (เผื่อ safe-area iOS) ---- */
    .save-bar {
        background: var(--color-surface);
        border-top: 1px solid var(--color-border);
        padding: 10px var(--space-3) calc(10px + env(safe-area-inset-bottom, 0px));
        box-shadow: var(--shadow-md);
        /* คำโปรยขึ้นบรรทัดเต็มความกว้าง แล้วปุ่มเรียงเป็นแถวด้านล่าง — กันปุ่มยืดสูงผิดรูป */
        flex-wrap: wrap;
        align-items: center;
    }
    /* ข้อความอธิบาย: กินเต็มความกว้าง เป็นบรรทัดของตัวเอง (ไม่บีบเป็นคอลัมน์แคบ) */
    .save-bar > .text-muted {
        flex: 1 1 100%;
        text-align: center;
        margin-bottom: 2px;
    }
    .save-bar .btn-app { flex: 1; min-height: 48px; }

    /* ---- หน้านับสต๊อก: save bar ที่มีปุ่ม "ส่งอนุมัติ" ----
       สถานะ auto-save เป็นบรรทัดบนตัวเล็ก (ไม่แย่งความกว้างปุ่ม) แล้วปุ่ม 2 ตัวแบ่งครึ่งแถวเดียว
       ปุ่ม 44px + สถานะ 1 บรรทัด = สูงรวม ~78px ยังเหลือพื้นที่อ่านรายการนับ */
    .save-bar:has(.count-approve-btn) { padding-top: 6px; gap: 6px; }
    .save-bar:has(.count-approve-btn) .count-save-status {
        flex: 1 1 100%;
        margin-right: 0;
        justify-content: center;
        font-size: 11px;
        line-height: 1.2;
    }
    .save-bar .count-save-btn,
    .save-bar .count-approve-btn {
        flex: 1 1 0;
        min-width: 0;
        min-height: 44px;
        justify-content: center;
        white-space: nowrap;
    }

    .empty-state { padding: 56px 28px; }

    /* ---- Dashboard = กริดไอคอนเมนูแบบ home ของแอป ---- */
    .home-head { padding: 4px 2px 10px; }
    .home-head__eyebrow {
        font-family: var(--ff-mono);
        font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
        color: var(--color-faint);
    }
    .home-head__title { font-size: 20px; font-weight: 700; margin: 2px 0 0; }
    .home-head__count { font-size: 12px; color: var(--color-muted); margin-top: 2px; }

    .menu-section-label {
        font-family: var(--ff-mono);
        font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
        color: var(--color-faint); margin: 14px 2px 8px;
    }
    .menu-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
    .menu-tile {
        position: relative;
        min-width: 0;
        aspect-ratio: 1 / 1;
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        padding: 12px 8px;
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
        text-align: center;
        text-decoration: none; color: var(--color-text);
        box-shadow: var(--shadow-sm);
    }
    .menu-tile:active { background: var(--color-surface-alt); transform: scale(0.98); }
    .menu-tile__glyph {
        width: 58px; height: 58px; border-radius: var(--radius-lg);
        display: flex; align-items: center; justify-content: center;
        font-size: 34px; color: var(--color-primary-hover); background: transparent;
    }
    .menu-tile__label { font-size: 13px; font-weight: 600; line-height: 1.2; max-width: 100%; overflow-wrap: anywhere; }

    /* ทางลัดด่วน (ปุ่มงานที่ทำบ่อย) เหนือกริดเมนู — action-first */
    .home-quick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .home-quick__btn {
        display: flex; align-items: center; gap: 10px;
        min-height: 54px; padding: 12px 14px;
        border: 1px solid var(--color-border-strong);
        border-radius: var(--radius-lg);
        /* พื้นหลังเข้มพอให้เห็นชัดบนธีมโทนเทา — color-mix ทำให้ปรับตามสี primary ของแต่ละธีมเอง
           (fallback เป็นเทาอ่อนสำหรับเบราว์เซอร์ที่ไม่รองรับ color-mix) */
        background: #e6e8ea;
        background: color-mix(in srgb, var(--color-primary) 12%, var(--color-surface));
        color: var(--color-primary-hover);
        box-shadow: var(--shadow-sm);
        text-decoration: none; font-weight: 600; font-size: 14px;
    }
    .home-quick__btn i { font-size: 20px; color: var(--color-primary); }
    .home-quick__btn:active { transform: scale(0.98); }

    /* หัวข้อ "ทางลัดด่วน" + ปุ่มตั้งค่า (มือถือ) */
    .menu-section-label--action { display: flex; align-items: center; justify-content: space-between; }
    .quick-cfg-btn {
        border: 0; background: transparent; color: var(--color-primary-hover);
        font-size: 16px; line-height: 1; padding: 4px 6px; cursor: pointer;
        display: inline-flex; align-items: center; border-radius: var(--radius-md);
    }
    .quick-cfg-btn:active { background: var(--color-primary-soft); }
    .menu-tile__badge {
        position: absolute; top: 8px; right: 8px;
        min-width: 20px; height: 20px; padding: 0 5px;
        border-radius: 10px; background: var(--color-primary); color: #fff;
        font-family: var(--ff-mono); font-size: 11px; font-weight: 700;
        display: flex; align-items: center; justify-content: center;
    }

    /* ---- sidebar drawer ---- */
    .nav-group__label {
        font-family: var(--ff-mono);
        text-transform: uppercase; letter-spacing: 0.06em; font-size: 10px;
    }
    .nav-item.active { background: var(--color-primary-soft); color: var(--color-primary-hover); }
}

/* จอเล็กมาก: ลิสต์การ์ดเต็มกว้างแนบขอบ */
@media (max-width: 600px) {
    .table-scroll { overflow: visible; }

    /* Report grids can be wider than the mobile viewport. Keep their own
       horizontal scroller because html/body overflow is intentionally hidden. */
    .table-scroll.report-scroll {
        max-width: 100%;
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y;
    }
}

/* ============================================================
   App-Like Kit (PlanAppLikeMobileUI Phase 1) — mobile behavior
   • overflow guard กัน body เลื่อนแนวนอน
   • touch target อย่างน้อย 44px
   • filter drawer = bottom sheet (opt-in ผ่าน data-filter-drawer)
   • bottom action bar ติดล่างจอ + safe-area
   ============================================================ */
@media (max-width: 992px) {

    /* ---- Overflow guard: ไม่ให้ body เลื่อนแนวนอน (ตารางที่ต้องเลื่อนใช้ .table-scroll เอง) ---- */
    html, body { overflow-x: hidden; }
    .app-content { max-width: 100%; }
    .app-content img:not(.no-fit) { max-width: 100%; height: auto; }
    .app-content img.count-row__img {
        display: block;
        width: 64px;
        max-width: 64px;
        height: 64px;
        object-fit: cover;
        object-position: center;
    }
    .app-content pre { white-space: pre-wrap; word-break: break-word; }

    /* ---- Touch target: ปุ่ม/ลิงก์สำคัญแตะได้ง่าย ---- */
    .btn-icon-app { min-width: 40px; min-height: 40px; }
    /* paging: กระชับให้พอดีจอแคบ (เลขหน้าเยอะ) — ยังแตะง่ายพอ ~34px */
    .pagination-app__pages a, .pagination-app__pages span {
        min-width: 34px; height: 34px; padding: 0 4px; font-size: 13px;
    }
    .pagination-app { flex-wrap: wrap; gap: var(--space-2); }
    .pagination-app__pages { gap: 3px; }

    /* ---- Filter trigger: แสดงปุ่มแทน filter-bar ที่ opt-in ---- */
    .filter-bar[data-filter-drawer] { display: none; }
    .filter-trigger {
        display: inline-flex; align-items: center; gap: 6px;
        min-height: 44px; padding: 0 14px; margin-bottom: var(--space-4);
        border: 1px solid var(--color-border-strong); border-radius: var(--radius-md);
        background: var(--color-surface); color: var(--color-text);
        font-size: var(--fs-base); font-weight: 600; cursor: pointer;
    }
    .filter-trigger:active { background: var(--color-surface-alt); }
    .filter-trigger__badge {
        min-width: 20px; height: 20px; padding: 0 5px;
        border-radius: 10px; background: var(--color-primary); color: #fff;
        font-family: var(--ff-mono); font-size: 11px; font-weight: 700;
        display: inline-flex; align-items: center; justify-content: center;
    }

    /* ---- Filter top sheet: เปิดจากด้านบน (กันชนกับแป้นพิมพ์มือถือที่เด้งจากด้านล่าง) ---- */
    .filter-bar[data-filter-drawer].filter-bar--open {
        display: block;
        position: fixed; left: 0; right: 0; top: 0;
        z-index: 1050;
        max-height: 85vh; overflow-y: auto;
        border-radius: 0 0 var(--radius-lg) var(--radius-lg);
        border: 1px solid var(--color-border);
        padding-top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
        box-shadow: var(--shadow-md);
        animation: filter-sheet-down 0.18s ease;
    }
    @keyframes filter-sheet-down { from { transform: translateY(-100%); } to { transform: translateY(0); } }
    body.filter-sheet-open { overflow: hidden; }
    body.filter-sheet-open::after {
        content: ""; position: fixed; inset: 0;
        background: rgba(15, 23, 42, 0.4); z-index: 1040;
    }

    /* ---- Bottom action bar: ติดล่างจอ + safe-area iOS ---- */
    .action-bar {
        position: sticky; bottom: 0;
        padding: 10px var(--space-3) calc(10px + env(safe-area-inset-bottom, 0px));
        box-shadow: var(--shadow-md);
        gap: var(--space-2);
    }
    .action-bar .btn-app { flex: 1; min-height: 48px; }

    /* ---- กันปุ่มย้อนกลับซ้ำ: มี back ที่ app-bar (มุมซ้ายบน) แล้ว จึงซ่อนปุ่ม "กลับ" ในหน้า ----
       ใช้ .bi-arrow-left ซึ่งเป็น class token เดียว จึงไม่โดน .bi-arrow-left-right (ไอคอนโอนของ) */
    .page-header__actions a:has(> i.bi-arrow-left) { display: none; }
    /* ถ้า header actions เหลือแต่ปุ่มกลับที่ถูกซ่อน → ยุบ container กันเกิดช่องว่าง */
    .page-header__actions:has(a > i.bi-arrow-left):not(:has(> :not(:has(i.bi-arrow-left)))) {
        display: none;
    }

    /* ---- ปุ่ม "สร้าง/เพิ่ม" ในหัวหน้า → ลอยเป็น FAB มุมขวาล่าง (ลดความรกด้านบน) ----
       เจาะเฉพาะปุ่ม primary ที่ไอคอนเป็นแบบ "เพิ่ม/สร้าง" (plus-lg / shield-plus / person-plus)
       จึงไม่โดนปุ่ม บันทึก (bi-save) ของหน้าตั้งค่า, ปุ่ม กลับ/ลบ (btn-outline-app),
       หรือปุ่มค้นหา (อยู่ใน .filter-bar).
       z-index 1000 < backdrop ของ filter sheet (1040) → เปิดตัวกรองแล้ว FAB ถูกบังถูกต้อง */
    .page-header__actions .btn-primary-app:has(> i.bi-plus-lg),
    .page-header__actions .btn-primary-app:has(> i.bi-shield-plus),
    .page-header__actions .btn-primary-app:has(> i.bi-person-plus) {
        position: fixed;
        right: calc(var(--space-4) + env(safe-area-inset-right, 0px));
        bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
        z-index: 1000;
        width: 56px; height: 56px;
        min-height: 56px;
        padding: 0;
        gap: 0;
        border-radius: 50%;
        font-size: 0; /* ซ่อนข้อความ เหลือไอคอน (ชื่อยังอยู่ใน DOM = accessible name) */
        box-shadow: var(--shadow-lg);
        justify-content: center;
    }
    .page-header__actions .btn-primary-app:has(> i.bi-plus-lg) > i,
    .page-header__actions .btn-primary-app:has(> i.bi-shield-plus) > i,
    .page-header__actions .btn-primary-app:has(> i.bi-person-plus) > i {
        font-size: 24px;
        margin: 0;
    }
    /* ตอนเปิด bottom sheet ตัวกรอง ซ่อน FAB กันลอยทับ/รบกวน */
    body.filter-sheet-open .page-header__actions .btn-primary-app:has(> i.bi-plus-lg),
    body.filter-sheet-open .page-header__actions .btn-primary-app:has(> i.bi-shield-plus),
    body.filter-sheet-open .page-header__actions .btn-primary-app:has(> i.bi-person-plus) {
        display: none;
    }

    /* หน้าที่มี FAB (ปุ่มเพิ่มลอยมุมขวาล่าง) — เว้นที่ท้ายเนื้อหา ไม่ให้ FAB ลอยทับ
       pager (เลขหน้า) หรือปุ่มท้ายลิสต์ตอน scroll สุด */
    body:has(.page-header__actions .btn-primary-app > i.bi-plus-lg) .app-content,
    body:has(.page-header__actions .btn-primary-app > i.bi-shield-plus) .app-content,
    body:has(.page-header__actions .btn-primary-app > i.bi-person-plus) .app-content {
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }
}
