/* Giao diện cảm ứng cho ứng dụng nhân viên. Tách khỏi app.css để các override mobile/Fold
   có thể kiểm soát và hoàn tác độc lập, không đụng bố cục desktop đang vận hành. */
:root {
    --mobile-nav-h: 66px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

html {
    min-width: 0;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body { min-width: 0; }
.content-frame { width: 100%; max-width: 1600px; margin: 0 auto; min-width: 0; }
.mobile-bottom-nav, .mobile-sidebar-footer { display: none; }

.floating-alert-toasts {
    position: fixed;
    right: 20px;
    bottom: 90px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(340px, calc(100vw - 32px));
}

.pwa-header-link { white-space: nowrap; }
.wallart-pwa-standalone .pwa-header-link,
.wallart-pwa-standalone .login-install-link { display: none !important; }

.login-install-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid #e5e7eb;
    color: #2563eb;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

/* Trang cài app dùng được cả trước đăng nhập. */
.staff-install-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: max(24px, var(--safe-top)) max(16px, var(--safe-right)) max(24px, var(--safe-bottom)) max(16px, var(--safe-left));
    background: radial-gradient(circle at top left, #dbeafe 0, transparent 36%), #f5f7fb;
}

.staff-install-card {
    width: min(100%, 720px);
    padding: clamp(20px, 4vw, 36px);
    border: 1px solid #dbe3ee;
    border-radius: 22px;
    background: #fff;
    box-shadow: 0 20px 55px rgba(15, 23, 42, .13);
}

.staff-install-heading { display: flex; align-items: center; gap: 18px; margin-bottom: 22px; }
.staff-install-heading > img { flex: 0 0 auto; border-radius: 17px; box-shadow: 0 7px 18px rgba(15, 23, 42, .16); }
.staff-install-heading h1 { margin: 2px 0 4px; color: #0f172a; font-size: clamp(24px, 5vw, 34px); }
.staff-install-heading h1:focus { outline: 0; }
.staff-install-heading p { margin: 0; color: #64748b; font-size: 14px; line-height: 1.55; }
.staff-install-kicker { color: #2563eb !important; font-size: 11px !important; font-weight: 800; letter-spacing: .12em; }

.staff-pwa-prompt { margin: 0 0 18px; padding: 16px; border: 1px solid #bfdbfe; border-radius: 14px; background: #eff6ff; }
.staff-pwa-success { border-color: #bbf7d0; background: #f0fdf4; }
.staff-pwa-guide { border-color: #dbe3ee; background: #f8fafc; }
.staff-pwa-row { display: flex; align-items: center; gap: 14px; }
.staff-pwa-row-top { align-items: flex-start; }
.staff-pwa-icon { flex: 0 0 auto; border-radius: 13px; }
.staff-pwa-copy { flex: 1; min-width: 0; }
.staff-pwa-prompt strong { display: block; color: #0f172a; font-size: 16px; }
.staff-pwa-prompt p { margin: 3px 0 0; color: #64748b; font-size: 13px; line-height: 1.5; }
.staff-pwa-prompt ol { margin: 7px 0 0; padding-left: 19px; color: #475569; font-size: 13px; line-height: 1.55; }
.staff-pwa-install-button {
    min-height: 42px;
    flex: 0 0 auto;
    padding: 9px 16px;
    border: 0;
    border-radius: 10px;
    background: #1677ff;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
.staff-pwa-url { overflow-wrap: anywhere; color: #2563eb; }
.staff-install-note { padding: 12px 14px; border-radius: 11px; background: #fff7ed; color: #9a3412; font-size: 13px; line-height: 1.5; }
.staff-install-features { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.staff-install-features > div { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; padding: 13px; border: 1px solid #e5e7eb; border-radius: 12px; }
.staff-install-features > div > span { grid-row: 1 / span 2; font-size: 22px; }
.staff-install-features strong { font-size: 13px; color: #1e293b; }
.staff-install-features small { margin-top: 3px; color: #64748b; font-size: 11px; line-height: 1.4; }
.staff-install-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* Điện thoại + Fold mở: dùng drawer thay sidebar cố định. 1024px được chọn có chủ đích:
   Fold mở ngang thường rộng 720–960px, nếu dùng breakpoint 768 cũ sẽ rơi vào desktop chật. */
@media (max-width: 1023.98px) {
    :root { --header-h: 112px; }

    body {
        font-size: 14px;
        overflow-x: hidden;
        touch-action: manipulation;
    }

    .app-shell { min-height: 100vh; min-height: 100dvh; }
    .app-header {
        height: calc(var(--header-h) + var(--safe-top));
        padding-top: var(--safe-top);
    }

    .header-inner {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-rows: 58px 54px;
        width: 100%;
        padding: 0 max(10px, var(--safe-right)) 0 max(10px, var(--safe-left));
    }

    .mobile-menu-toggle {
        display: flex !important;
        grid-column: 1;
        grid-row: 1;
        align-self: center;
        margin: 0 8px 0 0;
    }

    .brand { grid-column: 2; grid-row: 1; min-width: 0; gap: 8px; }
    .brand-logo { width: auto; height: 32px; max-width: 54px; }
    .brand-text { min-width: 0; }
    .brand-name { display: block; overflow: hidden; color: #fff; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
    .brand-sub { font-size: 9px; }

    .header-center {
        display: flex !important;
        grid-column: 1 / -1;
        grid-row: 2;
        align-self: start;
        width: 100%;
        padding: 0 2px 8px;
    }
    .header-search-wrap { max-width: none; }
    .header-search { min-height: 42px; border-radius: 11px; background: rgba(255, 255, 255, .14); }
    .header-search-input { min-width: 0; padding: 9px 10px; font-size: 16px; }
    .search-dropdown {
        position: fixed;
        top: calc(var(--header-h) + var(--safe-top) - 4px);
        right: max(8px, var(--safe-right));
        left: max(8px, var(--safe-left));
        max-height: min(62vh, 480px);
        border-radius: 12px;
    }
    .search-item { min-height: 50px; padding: 9px 12px; }
    .search-item-title { font-size: 14px; }
    .search-item-sub { font-size: 12px; }

    .header-actions {
        grid-column: 3;
        grid-row: 1;
        align-self: center;
        justify-self: end;
        min-width: 0;
        gap: 3px;
    }
    .quick-actions, .header-user, .header-actions .shortcut-help-wrap,
    .header-actions > a[href="/changepassword"], .header-actions > form { display: none !important; }
    .header-actions .btn-header {
        width: 37px;
        height: 37px;
        justify-content: center;
        padding: 0;
        border-radius: 9px;
    }
    .pwa-header-text { display: none; }

    .app-body { min-height: calc(100dvh - var(--header-h)); }
    .app-sidebar,
    .app-sidebar.collapsed {
        position: fixed;
        top: calc(var(--header-h) + var(--safe-top));
        bottom: 0;
        left: 0;
        z-index: 1050;
        width: min(82vw, 330px);
        padding-bottom: calc(var(--safe-bottom) + 12px);
        transform: translateX(-105%);
        transition: transform .25s cubic-bezier(.4, 0, .2, 1);
        box-shadow: none;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .app-sidebar.mobile-open { transform: translateX(0); box-shadow: 8px 0 30px rgba(15, 23, 42, .24); }
    .app-sidebar.collapsed .nav-text,
    .app-sidebar.collapsed .section-title { display: revert; width: auto; height: auto; margin-bottom: 6px; padding-left: 10px; opacity: 1; font-size: revert; }
    .app-sidebar.collapsed .nav-item-link { justify-content: flex-start; padding: 9px 12px; }
    .app-sidebar.collapsed .nav-icon { width: 24px; font-size: 17px; }
    .app-sidebar .sidebar-toggle, .sidebar-resizer { display: none !important; }
    .sidebar-backdrop {
        display: block;
        position: fixed;
        top: calc(var(--header-h) + var(--safe-top));
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1040;
        background: rgba(15, 23, 42, .52);
        backdrop-filter: blur(2px);
    }
    .mobile-sidebar-footer {
        display: grid;
        gap: 3px;
        margin: 10px 8px 0;
        padding-top: 10px;
        border-top: 1px solid #e5e7eb;
    }
    .mobile-sidebar-action {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        min-height: 44px;
        padding: 9px 12px;
        border: 0;
        border-radius: 8px;
        background: transparent;
        color: #334155;
        font-size: 14px;
        text-align: left;
        text-decoration: none;
    }
    .mobile-sidebar-action:hover { background: #f1f5f9; color: #0f172a; }
    .mobile-sidebar-logout { color: #b91c1c; }

    .app-content {
        width: 100% !important;
        min-width: 0;
        margin-left: 0 !important;
        padding: 9px max(8px, var(--safe-right)) calc(var(--mobile-nav-h) + var(--safe-bottom) + 13px) max(8px, var(--safe-left));
        overflow: visible;
    }
    .content-frame, article { min-width: 0; max-width: 100%; }

    .breadcrumb-nav {
        margin: -9px -8px 9px;
        padding: 7px 10px !important;
        overflow-x: auto;
        white-space: nowrap;
        scrollbar-width: none;
    }
    .breadcrumb-nav::-webkit-scrollbar { display: none; }

    .app-footer { display: none; }
    .mobile-bottom-nav {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1030;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        min-height: calc(var(--mobile-nav-h) + var(--safe-bottom));
        padding: 5px max(4px, var(--safe-right)) var(--safe-bottom) max(4px, var(--safe-left));
        border-top: 1px solid #dbe3ee;
        background: rgba(255, 255, 255, .97);
        box-shadow: 0 -7px 24px rgba(15, 23, 42, .10);
        backdrop-filter: blur(14px);
    }
    .mobile-bottom-item {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        min-width: 0;
        min-height: 54px;
        padding: 3px 2px;
        border: 0;
        border-radius: 9px;
        background: transparent;
        color: #475569;
        font: inherit;
        font-size: 10px;
        font-weight: 600;
        line-height: 1.15;
        text-decoration: none;
        cursor: pointer;
    }
    .mobile-bottom-item:active, .mobile-bottom-item:hover { background: #eff6ff; color: #1677ff; }
    .mobile-bottom-icon { position: relative; display: block; min-height: 25px; font-size: 20px; line-height: 25px; }
    .mobile-bottom-badge {
        position: absolute;
        top: -5px;
        right: -11px;
        min-width: 17px;
        height: 17px;
        padding: 0 4px;
        border: 2px solid #fff;
        border-radius: 10px;
        background: #dc2626;
        color: #fff;
        font-size: 9px;
        line-height: 13px;
    }

    /* Cỡ chữ và vùng chạm đủ lớn, đồng thời tránh iOS tự zoom khi focus input. */
    input:not([type="checkbox"]):not([type="radio"]), select, textarea,
    .form-control, .form-select, .dxbl-text-edit-input { font-size: 16px !important; }
    .btn:not(.btn-sm), .dxbl-btn:not(.dxbl-btn-sm) { min-height: 42px; }
    .btn-sm { min-height: 34px; }
    label, .form-label { font-size: 13px; }

    .app-content .row { --bs-gutter-x: 12px; --bs-gutter-y: 12px; }
    .app-content h1 { font-size: 1.55rem; }
    .app-content h2 { font-size: 1.35rem; }
    .app-content h3 { font-size: 1.2rem; }
    .app-content h4, .app-content h5 { font-size: 1.05rem; }
    .card { max-width: 100%; border-radius: 10px; }
    .card-header { padding: 11px 13px !important; }
    .card-body { padding: 13px !important; }
    .card-body.p-0 { padding: 0 !important; }
    .card-header.d-flex { flex-wrap: wrap; gap: 8px; }

    /* Không ép 8–15 cột vào màn hình hẹp: giữ độ đọc được và cho vuốt ngang. */
    .dxbl-grid {
        display: block !important;
        width: 100% !important;
        max-width: calc(100vw - 16px);
        overflow-x: auto !important;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    .dxbl-grid .dxbl-table { width: max-content !important; min-width: 720px; }
    .dxbl-grid .dxbl-table > thead > tr > th,
    .dxbl-grid .dxbl-table > tbody > tr > td { min-height: 42px; padding: 8px 9px !important; font-size: 12px !important; }
    .dxbl-grid .dxbl-grid-pager { position: sticky; left: 0; min-width: min(100vw - 18px, 720px); }
    .table-responsive { max-width: 100%; -webkit-overflow-scrolling: touch; }
    article table.table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    article table.table th, article table.table td { min-height: 40px; padding: 8px 9px; font-size: 12px; }

    .modal-dialog { width: auto; max-width: calc(100vw - 16px); margin: 8px auto; }
    .modal-content { max-height: calc(100dvh - 16px); overflow: auto; border-radius: 13px; }
    .dxbl-popup, .dxbl-modal { max-width: calc(100vw - 16px) !important; max-height: calc(100dvh - 16px) !important; }

    .portal-alert-panel {
        position: fixed !important;
        top: calc(var(--header-h) + var(--safe-top) + 5px) !important;
        right: max(8px, var(--safe-right)) !important;
        bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 7px);
        left: max(8px, var(--safe-left)) !important;
        width: auto !important;
        max-height: none;
        display: flex;
        flex-direction: column;
    }
    .portal-alert-list { max-height: none !important; flex: 1; }
    .portal-alert-item { min-height: 62px; }

    .floating-alert-toasts {
        right: max(9px, var(--safe-right));
        bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 10px);
        left: max(9px, var(--safe-left));
        width: auto;
        max-width: none;
    }
    .scroll-top-button {
        right: max(12px, var(--safe-right)) !important;
        bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 14px) !important;
    }
    #mh-reconnect-toast {
        top: calc(var(--safe-top) + 8px) !important;
        right: max(8px, var(--safe-right)) !important;
        left: max(8px, var(--safe-left)) !important;
        max-width: none !important;
    }

    .login-wrap { min-height: 100vh; min-height: 100dvh; padding: max(16px, var(--safe-top)) max(12px, var(--safe-right)) max(16px, var(--safe-bottom)) max(12px, var(--safe-left)); }
    .login-box { width: min(100%, 420px); padding: 26px 20px; border-radius: 16px; }
    .login-logo { margin-bottom: 15px; }
    .login-logo img { height: 42px; }

    .home-banner-card .card-body { padding: 16px !important; }
    .home-banner-card h3 { font-size: 1.25rem; }
    .home-banner-card .d-flex.gap-2 { width: 100%; }
    .home-banner-card .d-flex.gap-2 > * { flex: 1 1 0; }
}

/* Fold mở dọc / tablet nhỏ: khoảng thở lớn hơn điện thoại nhưng vẫn dùng drawer và thanh đáy. */
@media (min-width: 600px) and (max-width: 1023.98px) {
    .app-content { padding-right: max(16px, var(--safe-right)); padding-left: max(16px, var(--safe-left)); }
    .content-frame { max-width: 960px; }
    .mobile-bottom-nav { right: 50%; left: auto; width: min(760px, 100%); transform: translateX(50%); border-right: 1px solid #dbe3ee; border-left: 1px solid #dbe3ee; border-radius: 14px 14px 0 0; }
    .card-body { padding: 17px !important; }
    .staff-install-features { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Fold mở ngang: đủ chỗ để search cùng một hàng, trả lại 48px chiều cao nội dung. */
@media (min-width: 768px) and (max-width: 1023.98px) and (orientation: landscape) {
    :root { --header-h: 64px; }
    .header-inner { grid-template-columns: auto auto minmax(220px, 1fr) auto; grid-template-rows: 64px; gap: 10px; }
    .mobile-menu-toggle { grid-column: 1; grid-row: 1; }
    .brand { grid-column: 2; grid-row: 1; }
    .brand-sub { display: none; }
    .header-center { grid-column: 3; grid-row: 1; align-self: center; padding: 0; }
    .header-actions { grid-column: 4; grid-row: 1; }
    .search-dropdown { top: calc(var(--header-h) + var(--safe-top) - 3px); left: 28%; }
}

/* Fold gập/mở khi xoay ngang thường chỉ còn 360–480px chiều cao. Thu gọn màn hình
   đăng nhập để nút đăng nhập và cài app vẫn nằm trong cùng một khung nhìn. */
@media (max-width: 1023.98px) and (max-height: 520px) and (orientation: landscape) {
    .login-wrap { align-items: flex-start; padding: max(8px, var(--safe-top)) max(12px, var(--safe-right)) max(8px, var(--safe-bottom)) max(12px, var(--safe-left)); }
    .login-box { padding: 10px 20px; }
    .login-logo { margin-bottom: 3px; }
    .login-logo img { height: 28px; }
    .login-title { margin-bottom: 1px; font-size: 16px; }
    .login-sub { margin-bottom: 7px; }
    .login-box .form-group { margin-bottom: 7px; }
    .login-box .form-label { margin-bottom: 2px; }
    .login-box .form-input { min-height: 38px; padding: 6px 10px; }
    .login-box .btn-login { min-height: 38px; margin-top: 1px; padding: 6px; }
    .login-box .passkey-login { margin-top: 5px; }
    .login-install-link { margin-top: 6px; padding-top: 6px; }
}

@media (max-width: 599.98px) {
    .staff-install-page { place-items: start center; }
    .staff-install-card { padding: 19px 16px; border-radius: 16px; }
    .staff-install-heading { align-items: flex-start; gap: 12px; }
    .staff-install-heading > img { width: 58px; height: 58px; border-radius: 13px; }
    .staff-install-heading h1 { font-size: 24px; }
    .staff-install-features { grid-template-columns: 1fr; }
    .staff-install-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .staff-pwa-row { align-items: flex-start; flex-wrap: wrap; }
    .staff-pwa-install-button { width: 100%; }
}

@media (max-width: 380px) {
    .brand-logo { height: 30px; max-width: 42px; }
    .brand-sub { display: none; }
    .brand-name { font-size: 10px; letter-spacing: .04em; }
    .header-actions .btn-header { width: 34px; height: 34px; }
    .pwa-header-link { display: none !important; }
    .mobile-bottom-item { font-size: 9px; }
    .mobile-bottom-icon { font-size: 19px; }
    .app-content { padding-right: max(6px, var(--safe-right)); padding-left: max(6px, var(--safe-left)); }
}

/* Khi bàn phím ảo chiếm gần hết màn hình, bỏ thanh đáy để không che trường đang nhập. */
@media (max-width: 767.98px) and (max-height: 480px) {
    .mobile-bottom-nav { display: none; }
    .app-content { padding-bottom: 12px; }
    .floating-alert-toasts { bottom: 10px; }
}

@media (display-mode: standalone) {
    .app-header { padding-top: var(--safe-top); }
    .app-sidebar { padding-bottom: calc(var(--safe-bottom) + 12px); }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar, .app-content, .mobile-bottom-item, .card { transition: none !important; }
}
