/* ==========================================================================
   TỐI ƯU GIAO DIỆN MOBILE (CHUNG CHO TOÀN BỘ HỆ THỐNG)
   ========================================================================== */
@media (max-width: 768px) {

    /* --- [1] CẤU TRÚC KHUNG TRANG CHÍNH & MENU ĐÁY --- */
    body {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    .main {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        padding: 16px;
        padding-bottom: 85px;
        overflow-y: auto;
        box-sizing: border-box;
        z-index: 1;
    }

    .sb {
        width: 100%;
        height: auto;
        flex-direction: row !important;
        padding: 0;
        border-right: none;
        border-top: none;
        position: fixed;
        bottom: 0;
        left: 0;
        background: transparent;
        align-items: stretch;
        justify-content: space-between;
        z-index: 999;
    }

    .logo {
        display: none;
    }

    .menu {
        flex-direction: row;
        width: 66.66%;
        gap: 0;
    }

    .m-btn {
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: var(--f-size-xs-fine) !important; /* Đã đổi (10px -> quy về biến nhỏ 10.5px cho mịn) */
        padding: 12px 0 !important;
        width: 50% !important;
        border-radius: 0;
        gap: 4px !important;
        text-align: center !important;
        background: var(--sf);
        border-top: 1px solid var(--b);
    }

    .m-btn.active {
        background: var(--bg) !important;
        color: var(--p) !important;
    }

    .logout-btn {
        margin-top: 0 !important;
        width: 33.33% !important;
        border-radius: 0;
        background: var(--sf) !important;
        border-top: 1px solid var(--b);
        border-left: 1px solid var(--b);
        padding: 12px 0 !important;
    }

    .usr-bar {
        margin-bottom: 10px;
        font-size: var(--f-size-label); /* Đã đổi (12px) */
    }


    /* --- [2] PHÂN HỆ THU CHI (CUỘN TỰ NHIÊN) --- */
    .thuchi-workspace { 
        display: flex;
        flex-direction: column; 
        width: 100%;
        height: auto !important; 
        overflow-y: visible !important; 
        gap: 16px;
        padding: 12px;
        padding-bottom: 80px; 
        box-sizing: border-box;
    }

    #p-t .card { 
        grid-template-columns: 1fr; 
        height: auto; 
        padding: 16px; 
        row-gap: 12px; 
    }
    
    #p-t .card .seg, #p-t .card .btn-sm { 
        grid-column: span 1; 
    }
    
    #p-t .card .btn-sm { 
        width: 100%; 
        height: 44px; 
        margin-top: 4px; 
    }

    .thuchi-workspace-right { 
        display: flex;
        flex-direction: column;
        gap: 16px; 
        height: auto !important; 
        overflow: visible !important; 
    }

    .stat-sidebar { 
        order: 1; 
        height: auto;
        padding: 16px;
    }

    .quick-history { 
        order: 2; 
        height: auto !important; 
        max-height: 400px; 
        overflow-y: auto !important; 
        -webkit-overflow-scrolling: touch; 
        padding: 16px;
        padding-top: 0px; 
    }


    /* --- [3] PHÂN HỆ R199K (CHỐNG VỠ GIAO DIỆN) --- */
    .r199k-workspace {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        max-width: 100% !important;
        gap: 16px;
        padding: 0 4px; 
        box-sizing: border-box !important;
        overflow-x: hidden;
    }

    #p-g .card {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        padding: 16px 14px !important;
        row-gap: 12px !important; 
        height: auto !important;
        box-sizing: border-box !important;
    }

    #p-g .card .gr,
    #p-g .card .seg,
    #p-g .card .gr:has(#r-gid),
    #p-g .card .gr:has(#btn-add-r199k),
    .gr {
        grid-column: unset !important; 
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    #p-g .card .seg {
        margin: 0 auto 4px auto !important;
    }

    .gr input, 
    .gr select,
    .gr input[readonly] {
        width: 100% !important;
        max-width: 100% !important;
        display: block !important;         
        text-align: center !important;     
        font-size: var(--f-size-sm);    /* Đã đổi (13px) */        
        -webkit-text-fill-color: var(--t) !important; 
        opacity: 1 !important;             
        box-sizing: border-box !important; 
        height: 34px !important;
        line-height: 24px !important; 
        padding: 4px 10px !important;
        background: var(--input-bg) !important;
        border: 1px solid var(--b) !important;
        border-radius: 6px !important;
    }

    #r-start {
        display: flex !important;            
        align-items: center !important;      
        justify-content: center !important;  
        text-align: center !important;
        -webkit-appearance: none !important; 
        appearance: none !important;
        min-height: 34px !important;         
    }

    #r-start::-webkit-date-and-time-value {
        text-align: center !important;
        width: 100% !important;
        margin: 0 auto !important;
        display: block !important;
    }

    #r-start::-webkit-inner-spin-button,
    #r-start::-webkit-clear-button {
        display: none !important;
        -webkit-appearance: none !important;
    }

    #r-start::-webkit-calendar-picker-indicator {
        position: absolute !important;
        right: 12px !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    #p-g .card .btn-sm {
        height: 40px !important;              
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .r199k-sidebar {
        width: 100% !important;
        height: auto !important;
        margin-bottom: 30px;
        box-sizing: border-box !important;
    }


    /* --- [4] TOAST NOTIFICATION MOBILE --- */
    #toast-container {
        top: 16px;
        right: 16px;
        left: 16px;
        width: auto;
        max-width: none;
    }

    .toast-item {
        font-size: var(--f-size-sm);    /* Đang dùng biến (13px) */
        padding: 14px 16px;
        border-radius: var(--r);
        animation: mobileSlideIn .4s cubic-bezier(.16,1,.3,1) forwards;
    }

    .toast-item.fade-out {
        animation: mobileSlideOut .35s cubic-bezier(.16,1,.3,1) forwards !important;
    }

    /* --- [5] TỐI ƯU Ô GỢI Ý GHI CHÚ CHỈ TRÊN MOBILE --- */
    #gc::-webkit-calendar-picker-indicator {
        display: none !important;
        -webkit-appearance: none !important;
        appearance: none !important;
        opacity: 0 !important;
        width: 0 !important;
        height: 0 !important;
    }
    #gc {
        -webkit-appearance: none !important;
        appearance: none !important;
    }
}

/* ==========================================================================
   ANIMATION KEYFRAMES MOBILE (Đặt ngoài @media để trình duyệt biên dịch chuẩn)
   ========================================================================== */
@keyframes mobileSlideIn {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes mobileSlideOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(-30px) scale(.95);
    }
}
